4

The Problem

In my iOS app, users login with Facebook through a UIWebView. Occasionally, instead of a login page, Facebook shows the message "Not Logged In":

enter image description here

I can reproduce the problem every time with a few lines of code:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{
    UIWebView* web = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 320, 400)];
    [self.window addSubview:web];
    NSString* url = @"https://m.facebook.com/dialog/oauth?client_id=9999999999999999&redirect_uri=https%3A%2F%2Fmysite.com%2FApp%2FFacebookLogin%2FCallback&response_type=code&scope=read_stream%2Cuser_about_me%2Coffline_access%2Cpublish_actions%2Cpublish_stream%2Cemail";        
    [web loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

What I've Tried

If I open that same URL in mobile safari using [[UIApplication sharedApplication] openUrl:...] then it works. It shows a login page with no problems.

If I change the scope to 'email' then it works in the web view with no problems. If I change it by adding an item, then it still breaks.

I've tried clearing the cookies and the cache for the UIWebView and I've deleted the app & re-installed it to try to clear everything. None of that works.

If I change the url by adding &state=abcd to force the browser to reload the request, it still breaks. This has no effect.

If I use the domain www.facebook.com instead of m.facebook.com then it works.

If I log shouldstartloadwithrequest on the UIWebView, it shows that the url loads then it loads again. In other words, facebook seems to be redirecting to itself.

Also, I've file a bug with Facebook (https://developers.facebook.com/bugs/452609994811240) & they've moved it to 'medium', so it may just be a bug on their system.

Any idea how I can get the login page to show without messing with the scope?

Community
  • 1
  • 1
bendytree
  • 13,095
  • 11
  • 75
  • 91

0 Answers0