7

I am trying to load a UIWebView with the Facebook OAuth authorization URL and I am using the following code. When my UIWebView loads with Facebook login page, I enter my credentials, then press the "Log in" button. When I hit the button I am getting the following error:

WebKit discarded an uncaught exception in the webView:decidePolicyForNavigationAction:request:frame:decisionListener:delegate: Application tried to present modally an active controller .

This same code works fine with iOS 4.3 and previous versions, but it doesn't work in iOS 5.0. I don't understand the problem, can anyone please help me?

NSString *redirectUrlString = @"http://www.facebook.com/connect/login_success.html";
NSString *authFormatString = @"https://graph.facebook.com/oauth/authorize?client_id=%@&redirect_uri=%@&scope=%@&type=user_agent&display=touch";

NSString *urlString = [NSString stringWithFormat:authFormatString, _apiKey, redirectUrlString, _requestedPermissions];
NSURL *url = [NSURL URLWithString:urlString];

NSLog(@"NSURL: %@", urlString);

NSURLRequest *request = [NSURLRequest requestWithURL:url];
[_webView loadRequest:request];
jscs
  • 63,694
  • 13
  • 151
  • 195
AAV
  • 3,785
  • 8
  • 32
  • 59

2 Answers2

22

Are you using the Ray Wenderlich code? (FBFunLoginDialog).. I found that this fixes it:

-(void)checkLoginRequired:(NSString *)urlString {
    NSLog(@"Url: %@",urlString);
    if ([urlString rangeOfString:@"login.php"].location != NSNotFound && [urlString rangeOfString:@"refid"].location == NSNotFound) {
            [_delegate displayRequired];
    } else if ([urlString rangeOfString:@"user_denied"].location != NSNotFound) {
         [_delegate closeTapped];
    }
}
Karl Goodhew
  • 236
  • 2
  • 2
  • Thank you so much Karl Goodhew! – Tuyen Nguyen Feb 25 '12 at 05:20
  • now i am getting this error what to do please help SECURITY WARNING:"Please treat the URL above as you would your password and do not share it with anyone. i searched so much on net but nothing works some says change url from http to https and some say in facebook account disable secure browsing but these all things are not working. any help – Prakash Desai May 28 '13 at 06:53
0

I have the same problem. I try to present view controller just after dismissing.

[self dismissModalViewControllerAnimated:YES];

When I try to do it without animation it works perfectly. use dismissViewControllerAnimated:completion:

Danil
  • 1,780
  • 17
  • 24