Sign in with Facebook on the UIwebView App

In my rails user application, Facebook usage is logged. And it works great.

Now I plan to have an iOS ( UIWebView app) application for my rails application. i.e. loading my website inside a webview.

My concern is that should I have one view controllerone that loads the website or two view controllers, first for my own login to FB using iOS FB SDKand another controller to load the website?

Currently, I tried with one controller, and when I click on Login using Facebook(which is located on the website) in the iOS application, Facebook login opens in safari and after entering the credentials a blank page appears indefinitely.

+4
source share
2 answers

Hi, you can watch one controller. You can refer to this tutorial to access Facebook. integrate login with fax book

Important steps

Step 1: create the Facebook application in the developer application and set up the info.plist file

Step 2: Login Action Code

- (IBAction)signInWithFacebookClicked:(id)sender {


    [FBSession openActiveSessionWithReadPermissions:@[@"public_profile",@"email",@"user_friends"]
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {


         // The session is open. Get the user information and update the UI.
         [FBRequestConnection startWithGraphPath:@"me"
                                      parameters:@{@"fields": @"first_name,last_name, email"}
                                      HTTPMethod:@"GET"
                               completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
                                   if (!error) {
                                       // Set the use full name.

                                       NSLog(@"FBresponse: =>%@",result);
                                   }
                                   else{
                                       NSLog(@"%@", [error localizedDescription]);
                                   }
                               }];
     }];
}

Step 3: Callback

- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{


    return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];

}



- (void)applicationDidBecomeActive:(UIApplication *)application
{


    // Handle the user leaving the app while the Facebook login dialog is being shown
    // For example: when the user presses the iOS "home" button while the login dialog is active
    [FBAppCall handleDidBecomeActive];

}

Step 4: Then process the FBSession block as per your requirement. hope this helps.

0
source

The problem is that iOS does not allow the use of a standalone UIWebView application. Therefore, a workaround:

Have two ViewController, 
    First ViewController would be used for native FB login.
    Second ViewController would load the webapp. 

This is how I developed the iOS UIWebview app with two ViewControllers.

0
source

Source: https://habr.com/ru/post/1620479/


All Articles