Logging into Facebook through Safari without using the installed application

I used the Facebook SDK from the Facebook developer portal and followed all the steps that were written, but when logging in via Facebook from my application, by default it uses Safari for the login procedure.

Why is he not using the installed application for this purpose?

+4
source share
1 answer

Try it.

-(IBAction)CLK_ConnectWithFB:(id)sender
{
    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
 // If the Facebook app is not installed on the device, falls back to \c FBSDKLoginBehaviorBrowser. This is the default behavior.
    login.loginBehavior = FBSDKLoginBehaviorNative;
    [login logInWithReadPermissions:@[@"email", @"user_friends",@"user_posts"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
     {
         if (error)
         {
             // Process error
             NSLog(@"error is :%@",error);
         }
         else if (result.isCancelled)
         {
             // Handle cancellations
             NSLog(@"error is :%@",error);
         }
         else
         {
             if ([result.grantedPermissions containsObject:@"email"])
             {
                 [self fetchUserInfo];
                 [login logOut];
             }
         }
     }];
}

-(void)fetchUserInfo
{
    if ([FBSDKAccessToken currentAccessToken])
    {
        [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id,name,link,first_name, last_name, picture.type(large), email, birthday, bio ,location ,friends ,hometown ,posts, friendlists"}]
         startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
             if (!error)
             {
                 NSLog(@"result is :%@",result);
                 NSLog(@"friend is :%@",[[result valueForKey:@"friends"]objectForKey:@"data"]);
                 NSString *photostring=[[[result valueForKey:@"picture"] objectForKey:@"data"] valueForKey:@"url"];
                 photostring = [photostring stringByReplacingOccurrencesOfString:@"&" withString:@"%26"];

                // [self Userlogin:[result valueForKey:@"email"] Username:[result valueForKey:@"name"] PhotoUrl:photostring LoginType:@"fb" Phoneno:@""];
             }
         }];          
    }
}
+3
source

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


All Articles