简体   繁体   English

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

[英]Facebook native login is not opening facebook app even if it's installed in device?

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

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. 我还检查了info.plist值中的错字错误。 and i can assure you they are correct. 我可以向你保证他们是对的。

Here is my code :- 这是我的代码: -

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

What am i missing ? 我错过了什么?

info.plist的屏幕截图

I have found a solution, but you should change something in FBSDKLogin pod. 我找到了解决方案,但您应该在FBSDKLogin pod中进行更改。 I was debugging the Pod and I realized that Facebook ask in the class FBSDKServerConfiguration for the server configuration for the app. 我正在调试Pod,我意识到Facebook在类FBSDKServerConfiguration询问应用程序的服务器配置。 It returns a JSON with some information to configure the Pod for our app. 它返回一个带有一些信息的JSON,以便为我们的应用程序配置Pod。 I realized that by default the JSON returns this dictionary: 我意识到默认情况下JSON返回这个字典:

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

By default the use_native_flow is 0, so when it saves the information in userDefaults for the next app launches. 默认情况下, use_native_flow为0,因此当它将信息保存在userDefaults以便下次启动应用程序时。 So, when the app calls FBSDKLoginMananger login method and checks for the loginBehaviour in this method, the variable useNativeDialog returns NO. 因此,当应用程序调用FBSDKLoginMananger登录方法并在此方法中检查loginBehaviour时,变量useNativeDialog将返回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: {
    .
    . 
    . 

}

As we see in the code, we know if the app is installed in this if, if ([FBSDKInternalUtility isFacebookAppInstalled]) . 正如我们在代码中看到的,我们知道应用程序是否安装在if if, if ([FBSDKInternalUtility isFacebookAppInstalled]) To solve the problem, I have changed this line 为了解决这个问题,我改变了这一行

BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];

to

 BOOL useNativeDialog = YES;

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. 我知道这不是一个好习惯,如果我更新这个Pod,它会改变,但至少是工作,我现在需要它。 I guess we can change that configuration in facebook developers admin site, but I haven't found anything. 我想我们可以在facebook开发者管理网站上更改该配置,但我还没有找到任何内容。

Facebook has changed Facebook login behavior for iOS9. Facebook改变了iOS9的Facebook登录行为。

Here is the quote from Facebook blog post : 以下是Facebook博客文章的引用:

We've been monitoring data and CTRs for over 250 apps over the last 6 weeks since iOS 9 launched. 自iOS 9推出以来,我们一直在监控超过250个应用的数据和点击率。 The click-through rate (CTR) of SVC Login outperforms the CTR of app-switch Login and is improving at 3x the rate of the app-switch experience. SVC登录的点击率(CTR)优于app-switch登录的点击率,并且以app-switch体验的3倍速度提升。 This indicates that the SVC experience is better for people and developers today, and will likely be the best solution in the long run. 这表明SVC体验对于今天的人和开发人员来说更好,并且从长远来看可能是最好的解决方案。 For this reason, the latest Facebook SDK for iOS uses SVC as the default experience for Login. 因此,最新的iOS SDK SDK使用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,
};

there is lot of behaviour available to access the fb login.try using alternate what you prefer from this. 有很多行为可以访问fb login.try使用备用你喜欢的东西。

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

Like this ...hope this will help you :) 喜欢这个...希望这会对你有所帮助:)

  • (FBSDKServerConfiguration *)_defaultServerConfigurationForAppID:(NSString *)appID { // Use a default configuration while we do not have a configuration back from the server. (FBSDKServerConfiguration *)_ defaultServerConfigurationForAppID:(NSString *)appID {//使用默认配置,而我们没有从服务器返回配置。 This allows us to set // the default values for any of the dialog sets or anything else in a centralized location while we are waiting for // the server to respond. 这允许我们在等待服务器响应时为任何对话集或集中位置中的任何其他设置//默认值。 static FBSDKServerConfiguration *_defaultServerConfiguration = nil; static FBSDKServerConfiguration * _defaultServerConfiguration = nil; if (![_defaultServerConfiguration.appID isEqualToString:appID]) { // Bypass the native dialog flow for iOS 9+, as it produces a series of additional confirmation dialogs that lead to // extra friction that is not desirable. if(![_ defaultServerConfiguration.appID isEqualToString:appID]){ //绕过iOS 9+的本机对话流,因为它会产生一系列额外的确认对话框,导致//额外的摩擦,这是不可取的。 NSOperatingSystemVersion iOS9Version = { .majorVersion = 9, .minorVersion = 0, .patchVersion = 0 }; NSOperatingSystemVersion iOS9Version = {。majorVersion = 9,.minorVersion = 0,.patchVersion = 0};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 IOS中的Facebook登录可以在模拟器上运行,但不能在安装了本机应用程序的设备上运行 - Facebook login in IOS works on emulator but not on device with native app installed iOS Facebook登录而无需打开浏览器或本机Facebook App - iOS Facebook Login Without Opening Browser or native Facebook App 使用本机应用程序登录Facebook - Login with facebook with native app Facebook在Z1BDF60599191919191919191919191CBDF8508204C4EBZ中通过Z26CAE7718C3218018019D6D6D4019D4019D4019D4019D4019D4019D4019D4019D4019D4019D19D4019D4019D19D19D19D19D20DB10C4NEC4EBZ登录失败 - Facebook sign-in in iOS fails when sign in through facebook app, it's working if the facebook app not installed in the device 如何在不打开Facebook应用程序的情况下登录Facebook? - How to Facebook login without opening Facebook app? 安装Facebook应用程序的Facebook SDK iOS登录 - Facebook SDK iOS login with Facebook app installed iOS:使用Facebook登录并打开Native Facebook应用程序 - iOS : Login with Facebook and open Native Facebook app 应用程序配置错误,安装Facebook登录IOS Facebook应用程序 - App is misconfigured for Facebook login IOS Facebook app installed Facebook通过Safari登录而不使用已安装的App - Facebook login through Safari not using installed App 安装了 FB 应用程序的 SwiftUI 自定义 Facebook 登录 - SwiftUI custom Facebook Login with FB app installed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM