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?
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?
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:@""];
}
}];
}
}