我创建了一个简单的测试html页面,其中包含类似于facebook的框。出于测试目的,我将测试页面上传到我的服务器。
在桌面上(从facebook退出)有以下情况:
但是,在Chrome浏览器的iphone上使用它并从facebook登出后会发生以下情况:
下面的屏幕截图显示了问题:
是否有可能避免这种情况?
编辑:当我在使用UIWebView的iOS应用程序中尝试此操作时,会发生同样的情况。
答案 0 :(得分:2)
好的,我在我的iOS应用程序中找到了一个解决方案,用于集成的UIWebView。
当某人未登录Facebook时,会打开一个弹出窗口并请求登录。登录后,用户被重定向回到他点击类似按钮的页面。但是在UIWebView中,此重定向URL会为用户留下空白页。该问题的解决方案是拦截重定向URL并使用类似按钮重新加载页面。
因此,使用UIWebView可以在加载实际网页之前拦截请求并对某些URL做出反应。这个代码看起来像这样:
- (void)viewDidLoad
{
[super viewDidLoad];
self.webview.delegate = self;
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com/facebook_like_box.html"]]];
}
- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
if( [[request.URL description] rangeOfString:@"lugins/close_popup.php"].location != NSNotFound) {
// We intercepted the redirect URL of facebook after logging in. Instead of loading a blank page recall the URL of the like box
// manually on the uiwebview.
[self.webview loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.example.com/facebook_like_box.html"]]];
//returning NO indicates the the page is not further loaded.
return NO;
}
//Any other page should be loaded
return YES;
}