问题
I'm using Facebook-iOS-SDK (4.0.1) for logging in with custom button. I'm implementing the following code
- (IBAction)fbButtonClicked:(UIButton *)sender {
FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
// Process error
} else if (result.isCancelled) {
// Handle cancellations
} else {
// If you ask for multiple permissions at once, you
// should check if specific permissions missing
if ([result.grantedPermissions containsObject:@"email"]) {
// Do work
if ([FBSDKAccessToken currentAccessToken]) {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me/friends" parameters:nil]
startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result2, NSError *error) {
if (!error) {
NSLog(@"fetched user:%@", result2);
}
}];
}
}
}
}];
}
if I have facebook app installed on a device then the code works fine. When I do not have facebook app installed, then the facebook is opened in a browser. Here, 'result.isCancelled' is set to 'YES' and I do not get a required result.
回答1:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
is required in appDelegate.m
回答2:
For me the reason was different
The following line caused result.isCancelled to always be true... idk why
[login logInWithReadPermissions:@[@"public_profile", @"email", @"gender"]
After changing to this... it worked
[login logInWithReadPermissions:@[@"public_profile"]
来源:https://stackoverflow.com/questions/29667307/using-facebook-ios-sdk-4-0-1-result-iscancelled-is-set-when-using-a-browser