簡體   English   中英

Facebook原生登錄即使安裝在設備中也不會打開Facebook應用程序?

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

我已經按照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];
                     }
                 }];
            }
        }
    }];

我錯過了什么?

info.plist的屏幕截圖

我找到了解決方案,但您應該在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以便下次啟動應用程序時。 因此,當應用程序調用FBSDKLoginMananger登錄方法並在此方法中檢查loginBehaviour時,變量useNativeDialog將返回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 if, if ([FBSDKInternalUtility isFacebookAppInstalled]) 為了解決這個問題,我改變了這一行

BOOL useNativeDialog = [serverConfiguration useNativeDialogForDialogName:FBSDKDialogConfigurationNameLogin];

 BOOL useNativeDialog = YES;

我知道這不是一個好習慣,如果我更新這個Pod,它會改變,但至少是工作,我現在需要它。 我想我們可以在facebook開發者管理網站上更改該配置,但我還沒有找到任何內容。

Facebook改變了iOS9的Facebook登錄行為。

以下是Facebook博客文章的引用:

自iOS 9推出以來,我們一直在監控超過250個應用的數據和點擊率。 SVC登錄的點擊率(CTR)優於app-switch登錄的點擊率,並且以app-switch體驗的3倍速度提升。 這表明SVC體驗對於今天的人和開發人員來說更好,並且從長遠來看可能是最好的解決方案。 因此,最新的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,
};

有很多行為可以訪問fb login.try使用備用你喜歡的東西。

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

喜歡這個...希望這會對你有所幫助:)

  • (FBSDKServerConfiguration *)_ defaultServerConfigurationForAppID:(NSString *)appID {//使用默認配置,而我們沒有從服務器返回配置。 這允許我們在等待服務器響應時為任何對話集或集中位置中的任何其他設置//默認值。 static FBSDKServerConfiguration * _defaultServerConfiguration = nil; if(![_ defaultServerConfiguration.appID isEqualToString:appID]){ //繞過iOS 9+的本機對話流,因為它會產生一系列額外的確認對話框,導致//額外的摩擦,這是不可取的。 NSOperatingSystemVersion iOS9Version = {。majorVersion = 9,.minorVersion = 0,.patchVersion = 0};

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM