Error logging into Facebook in UIWebView

In my application, I need to upload a webpage to UIWebView, where the user can log in with Facebook. The problem is that when the user clicks on the login, a blank page appears.

Can I go back to the first page and log in?

The web page works fine in Safari and opens a new window, and after logging in, it closes it and returns to where it left.

EDIT: Invalid URL was provided in UIWebView

+4
source share
3 answers

I think the facebook facebook SDK for iOS makes the magazine the way you want. See Link: facebook-iOS-SDK-sample: https://github.com/facebook/facebook-ios-sdk/tree/master/sample/Hackbook

Especially this part at https://github.com/facebook/facebook-ios-sdk/blob/master/sample/Hackbook/Hackbook/RootViewController.m

/** * Show the authorization dialog. */ - (void)login { HackbookAppDelegate *delegate = (HackbookAppDelegate *)[[UIApplication sharedApplication] delegate]; if (![[delegate facebook] isSessionValid]) { [[delegate facebook] authorize:permissions]; } else { [self showLoggedIn]; } } 

When you click on the login button, it will open the login dialog box and ask for permission. It looks like this: https://developers.facebook.com/docs/mobile/screenshots/ios/#iphone-native

I think the best way to implement a facebook-related application is to start with a Hacbook. This is a really nice and detailed sample.

+3
source

If you want to reload a specific URL after the facebook popup is closed to prevent it from getting stuck on a blank page, you can use this code.

First enable UIWebViewDelegate and set the delegate somewhere in your code.

 [yourwebView setDelegate:self]; 

Then use the shouldStartLoadWithRequest method to check the request URL for close_popup.php, which is used by Facebook to close their popup.

 - (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { NSString *urlString = [NSString stringWithFormat:@"%@", request]; if ([urlString rangeOfString:@"close_popup.php"].location == NSNotFound) { //The close_pop.php is not found. (Do nothing) } else { //Facebook closed the popup so we should load the page we now want the user to see. NSURL*url=[NSURL URLWithString:@"http://www.example.ca/thepageyouwanttoreload.html"]; NSURLRequest*request=[NSURLRequest requestWithURL:url]; [webView loadRequest:request]; } return YES; } 
+1
source

Problem with SSL? According to Joanne, use the facebook SDK and you get free additional functionality, including logging into the application through your own facebook application, if installed.

0
source

All Articles