简体   繁体   中英

Facebook login works in Safari but not in UIWebView

I have a an app with a UIWebView that displays a web page which has Facebook login. I'm using Facebook's JavaScript SDK (I cannot use the iOS SDK).

The login works perfectly when I open the site in mobile Safari but not in the web view. The login dialog opens, I enter the user credentials and it redirects to a blank white page. I know what causes this. Ina normal browser, this login dialog opens in a new window. But since UIWebView does not support multiple windows, the login replaces the webpage and once it is successfully logged in, it can't redirect back to the original web page.

I've searched all over SO for solutions but almost all of them are outdated. I don't think there is a straight forward fix for this but if anyone has a workaround/hack, please help me out.

Thank you.

Check if you added Facebook application ID (your app id) into Xcode project - app's url schema. Then make sure to redirect user back to your page after fb login.

      - (void)webViewDidFinishLoad:(UIWebView *)webView
            {

            NSString *url = [[webView.request URL] absoluteString];

          //  if([url hasPrefix:@"https://m.facebook.com/dialog/oauth"])
 if([url hasPrefix:@"https://m.facebook.com/home.php?"])

            {
            /* here you must implement method to send user to your page */
                [self backToMyPage]; 
            }
           }

           } 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM