0

I created a simple test html page that contains a facebook like box. For testing purpose I uploaed the test page to my server.

On the desktop (being log out of facebook) there is the following situation:

  1. Click on like
  2. A popup appears with a form for login
  3. After login the popup is closed and the like count is raised

However, using it on my iphone in chrome browser and being logged out of facebook the following happens:

  1. Click on the like button
  2. Redirect to the facebook login page
  3. After login I'm redirected to a blank page.

The screenshot below shows the problem: enter image description here

Is there a possibility to avoid this?

EDIT: The same happens when I try this in an iOS app using a UIWebView.

4

1 回答 1

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;
}
于 2013-08-26T17:40:52.127 回答