Facebook原生登录即使安装在设备中也不会打开Facebook应用程序?

时间:2015-11-28 13:14:50

标签: ios objective-c facebook-ios-sdk

我已经按照facebook-iso-sdk 4.8.0 for iOS 9的文档中描述的每个步骤进行了操作,但仍然无法在我的应用程序中使用“login-with-facebook”进行应用程序切换,即使facebook app是已安装。

正如您在下面的屏幕截图中看到的,我修改了info.plist,但仍然无法让原生应用程序切换工作。

我还检查了info.plist值中的错字错误。我可以向你保证他们是对的。

这是我的代码: -

    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];
                     }
                 }];
            }
        }
    }];

我缺少什么?

Screen Shot of info.plist

4 个答案:

答案 0 :(得分:9)

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

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

默认情况下,use_native_flow为0,因此当它将信息保存在userDefaults中以便下次启动应用时。 因此,当应用程序调用{​​{1}}登录方法并在此方法中检查loginBehaviour时,变量FBSDKLoginMananger将返回NO。所以交换机使用下一个案例。 useNativeDialog

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])

BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];

我知道这不是一个好习惯,如果我更新这个Pod,它会改变,但至少是工作,我现在需要它。 我想我们可以在facebook开发者管理网站上更改该配置,但我还没有找到任何内容。

答案 1 :(得分:8)

Facebook改变了iOS9的Facebook登录行为。

以下是Facebook blog post的引用:

  

自iOS 9发布以来,过去6周内,我们一直在监控超过250个应用的数据和点击率。 SVC登录的点击率(CTR)优于app-switch登录的点击率,并且以app-switch体验的3倍速度提升。这表明SVC体验对于今天的人和开发人员来说更好,并且从长远来看可能是最好的解决方案。因此,最新的iOS SDK SDK使用SVC作为登录的默认体验。

答案 2 :(得分:1)

typedef NS_ENUM(NSUInteger, FBSDKLoginBehavior)
{
  /*!
   @abstract This is the default behavior, and indicates logging in through the native
   Facebook app may be used. The SDK may still use Safari instead.
   */
  FBSDKLoginBehaviorNative = 0,
  /*!
   @abstract Attempts log in through the Safari or SFSafariViewController, if available.
   */
  FBSDKLoginBehaviorBrowser,
  /*!
   @abstract Attempts log in through the Facebook account currently signed in through
   the device Settings.
   @note If the account is not available to the app (either not configured by user or
   as determined by the SDK) this behavior falls back to \c FBSDKLoginBehaviorNative.
   */
  FBSDKLoginBehaviorSystemAccount,
  /*!
   @abstract Attemps log in through a modal \c UIWebView pop up

   @note This behavior is only available to certain types of apps. Please check the Facebook
   Platform Policy to verify your app meets the restrictions.
   */
  FBSDKLoginBehaviorWeb,
};

有很多行为可以访问fb login.try使用备用你喜欢的东西。

FBSDKLoginManager *loginmanager = [[FBSDKLoginManager alloc] init];
        loginmanager.loginBehavior=FBSDKLoginBehaviorNative;

喜欢这个...希望这会对你有所帮助:)。

答案 3 :(得分:1)

  • (FBSDKServerConfiguration *)_ defaultServerConfigurationForAppID:(NSString *)appID { //当我们没有从服务器返回配置时,使用默认配置。这允许我们设置 //我们等待时,任何对话框集或集中位置中的任何其他内容的默认值 //要响应的服务器 static FBSDKServerConfiguration * _defaultServerConfiguration = nil; if(![_ defaultServerConfiguration.appID isEqualToString:appID]){ //绕过iOS 9+的原生对话流,因为它会生成一系列其他确认对话框 //额外的摩擦是不可取的。 NSOperatingSystemVersion iOS9Version = {。majorVersion = 9,.minorVersion = 0,.patchVersion = 0};