Facebook的本地login是不是开放的Facebook应用程序,即使它安装在设备?

我已经按照facebook-iso-sdk 4.8.0 iOS 9文档中描述的每一步,但仍然不能在我的应用程序中执行“login-with-facebook”应用程序切换,即使Facebook应用程序已经安装。

正如你在下面的屏幕截图中所看到的,我已经修改了info.plist,但是仍然无法让原生应用切换到工作状态。

我也加倍检查了info.plist值中的input错误。 我可以向你保证他们是正确的。

这是我的代码:

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

我错过了什么?

info.plist的屏幕截图

我find了一个解决scheme,但是你应该改变FBSDKLogin窗格中的内容。 我正在debuggingPod,我意识到Facebook要求在类FBSDKServerConfiguration为应用程序的服务器configuration。 它返回一个带有一些信息的JSON来为我们的应用程序configurationPod。 我意识到,默认情况下,JSON返回这个字典:

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

默认情况下, use_native_flow是0,所以当它保​​存在userDefaults的信息为下一个应用程序启动。 所以,当应用程序调用FBSDKLoginManangerlogin方法并在此方法中检查loginBehaviour时,variablesuseNativeDialog返回NO。 所以交换机使用下一个案例。 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]; 

  BOOL useNativeDialog = YES; 

我知道这不是一个好的做法,如果我更新这个Pod,它会改变,但至less是工作,现在我需要它。 我想我们可以在Facebook开发人员pipe理站点更改该configuration,但我还没有find任何东西。

Facebook改变了iOS9的Facebooklogin行为。

这里是来自Facebook博客的引用:

自iOS 9发布以来,我们一直在监控过去6周内超过250个应用程序的数据和点击率。 SVClogin的点击率(CTR)优于应用程序切换login的点击率(CTR),提高了应用程序切换体验的3倍。 这表明SVC的经验对于今天的人们和开发者来说是更好的,从长远来看可能是最好的解决scheme。 出于这个原因,最新的Facebook SDK for iOS使用SVC作为Login的默认体验。

 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; 

像这样…希望这会帮助你:)

  • (FBSDKServerConfiguration *)_ defaultServerConfigurationForAppID:(NSString *)appID {//使用默认configuration,而没有从服务器返回configuration。 这使我们能够在我们等待//服务器响应的时候为任何对话集或其他任何集中位置设置默认值。 静态FBSDKServerConfiguration * _defaultServerConfiguration = nil; 如果(![_ defaultServerConfiguration.appID isEqualToString:appID]){ //绕过iOS 9+的原生对话stream,因为它会产生一系列额外的确认对话框,导致额外的摩擦,这是不可取的。 NSOperatingSystemVersion iOS9Version = {.majorVersion = 9,.minorVersion = 0,.patchVersion = 0};