facebook login on iphone leaves blank page

1.4k views Asked by At

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.

1

There are 1 answers

2
toom On BEST ANSWER

Okay, I found a solution for doing this in my iOS app for an integrated UIWebView.

When someone is not logged in to facebook a popup opens and requests a login. After logging in the user is redirected back to the page from where he hit the like button. However in the UIWebView this redirect URL leaves the user with a blank page. The solution to the problem is to intercept the redirect URL and reload the page with the like button.

So, with UIWebView one can intercept the requests before the actual webpage is loaded and react on certain URLs. The code for this look like this:

- (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;
}