4

I have used Facebook SDK from Facebook developer portal and completed all the steps which were written but during login through Facebook from my app by default it uses Safari for login procedure.

Why doesn't it use installed app for this purpose?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Subhash Kumar
  • 81
  • 1
  • 6
  • Looks like it's by design in iOS9 [Facebook Login - iOS 9 - Without Safari](http://stackoverflow.com/questions/32620002/facebook-login-ios-9-without-safari) – user499846 Nov 02 '15 at 21:42

1 Answers1

3

Try this.

-(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:@""];
             }
         }];          
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Rohit suvagiya
  • 1,005
  • 2
  • 12
  • 40