Using Facebook-iOS-SDK (4.0.1) result.isCancelled is set when using a browser

▼魔方 西西 提交于 2019-12-11 10:37:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!