即使已在设备中安装,Facebook本机登录也无法打开Facebook应用程序?

即使已在设备中安装,Facebook本机登录也无法打开Facebook应用程序?

问题描述:

我已经遵循iOS 9的facebook-iso-sdk 4.8.0文档中描述的每个步骤,但是即使facebook应用是已经安装.

i have followed every step described in the docs of facebook-iso-sdk 4.8.0 for iOS 9, but still couldn't preform app switch on "login-with-facebook" in my app, even if facebook app is already installed.

您可以在下面的屏幕截图中看到,我已经修改了info.plist,但仍然无法使本机应用程序切换正常工作.

As you can see in screen shot below i have modified info.plist, but still can't get native app switch to work.

我还仔细检查了info.plist值中的拼写错误.我可以向您保证它们是正确的.

I have also double checked for typo-mistakes in info.plist value. and i can assure you they are correct.

这是我的代码:-

    if (![AppDelegate SharedInstance].login) {
        [AppDelegate SharedInstance].login = [[FBSDKLoginManager alloc] init];
    }
    [AppDelegate SharedInstance].login.loginBehavior = FBSDKLoginBehaviorNative;
    [[AppDelegate SharedInstance].login logInWithReadPermissions:@[@"public_profile",@"email",@"user_friends"] fromViewController:self handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
        if (error) {

        }
        else if (result.isCancelled)
        {
            // Handle cancellations
        }
        else
        {
            NSLog(@"result.grantedPermissions == %@",result.grantedPermissions);
            if (result.token)
            {
                [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"id, name, email, first_name, last_name"}]
                 startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                     if (!error) {
                         NSLog(@"fetched user:%@", result);
                         NSString *userImageURL = [NSString stringWithFormat:@"https://graph.facebook.com/%@/picture?type=large", [result objectForKey:@"id"]];
                         [dictFacebookDetail addEntriesFromDictionary:result];
                         [dictFacebookDetail setObject:userImageURL forKey:@"profilepic"];
                         NSLog(@"facebook login result --- %@",dictFacebookDetail);
                         [self performSelectorInBackground:@selector(CheckFacebookUser:) withObject:dictFacebookDetail];
                     }
                 }];
            }
        }
    }];

我想念什么?

我找到了一个解决方案,但是您应该在FBSDKLogin窗格中进行一些更改.我在调试Pod时,我意识到Facebook在类FBSDKServerConfiguration中询问该应用程序的服务器配置.它返回带有一些信息的JSON,以为我们的应用配置Pod.我意识到默认情况下JSON返回此字典:

I have found a solution, but you should change something in FBSDKLogin pod. I was debugging the Pod and I realized that Facebook ask in the class FBSDKServerConfiguration for the server configuration for the app. It returns a JSON with some information to configure the Pod for our app. I realized that by default the JSON returns this dictionary:

 "ios_sdk_dialog_flows" =     {
        default =         {
            "use_native_flow" = 0;
            "use_safari_vc" = 1;
        };
        message =         {
            "use_native_flow" = 1;
        };
    };

默认情况下,use_native_flow为0,因此当它将信息保存在userDefaults中以供下次启动应用程序时使用. 因此,当应用程序调用FBSDKLoginMananger登录方法并在此方法中检查loginBehaviour时,变量useNativeDialog返回NO.因此,交换机使用下一种情况. case FBSDKLoginBehaviorBrowser:

By default the use_native_flow is 0, so when it saves the information in userDefaults for the next app launches. So, when the app calls FBSDKLoginMananger login method and checks for the loginBehaviour in this method, the variable useNativeDialog returns NO. So the switch uses the next case. case FBSDKLoginBehaviorBrowser:

- (void)logInWithBehavior:(FBSDKLoginBehavior)loginBehavior
{
.
.
...
  switch (loginBehavior) {
    case FBSDKLoginBehaviorNative: {
      if ([FBSDKInternalUtility isFacebookAppInstalled]) {
        [FBSDKServerConfigurationManager loadServerConfigurationWithCompletionBlock:^(FBSDKServerConfiguration *serverConfiguration, NSError *loadError) {
            BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];
          if (useNativeDialog && loadError == nil) {
            [self performNativeLogInWithParameters:loginParams handler:^(BOOL openedURL, NSError *openedURLError) {
              if (openedURLError) {
                [FBSDKLogger singleShotLogEntry:FBSDKLoggingBehaviorDeveloperErrors
                                   formatString:@"FBSDKLoginBehaviorNative failed : %@\nTrying FBSDKLoginBehaviorBrowser", openedURLError];
              }
              if (openedURL) {
                completion(YES, FBSDKLoginManagerLoggerAuthMethod_Native, openedURLError);
              } else {
                [self logInWithBehavior:FBSDKLoginBehaviorBrowser];
              }
            }];
          } else {
            [self logInWithBehavior:FBSDKLoginBehaviorBrowser];
          }
        }];
        break;
      }
      // intentional fall through.
    }
    case FBSDKLoginBehaviorBrowser: {
    .
    . 
    . 

}

正如我们在代码中所看到的,我们知道是否在以下情况下安装了该应用程序: if ([FBSDKInternalUtility isFacebookAppInstalled]). 为了解决这个问题,我更改了这一行

As we see in the code, we know if the app is installed in this if, if ([FBSDKInternalUtility isFacebookAppInstalled]). To solve the problem, I have changed this line

BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];

 BOOL useNativeDialog = YES;

我知道这不是一个好习惯,如果我更新此Pod,它将改变,但至少可以正常工作,我现在需要它. 我想我们可以在Facebook开发者管理站点中更改该配置,但是我什么都没找到.

I know this is not a good practice and it will change if I update this Pod, but at least is working and I needed it now. I guess we can change that configuration in facebook developers admin site, but I haven't found anything.