Facebook sdk没有使用已安装的应用程序登录iOS 10.0

时间:2016-12-02 09:13:24

标签: ios facebook

我想使用Facebook应用程序,如果它安装在我的iOS应用程序中通过Facebook登录的设备中。现在它是否重定向到safari浏览器,无论是否安装了应用程序?

任何帮助都将不胜感激。

感谢。

1 个答案:

答案 0 :(得分:0)

Facebook登录政策已更改。 iOS 10没有错。

参考 - https://developers.facebook.com/docs/facebook-login/ios

你必须像下面一样给予本地行为。

login.loginBehavior = FBSDKLoginBehaviorNative;

如果用户当时没有Facebook应用程序,请确保1件事。

好用。这将在app中的登录视图控制器上打开Facebook登录页面。

login.loginBehavior = FBSDKLoginBehaviorWeb;

示例代码

 FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];

    login.loginBehavior = FBSDKLoginBehaviorNative;

    [login
     logInWithReadPermissions: @[@"public_profile",@"email"]
     fromViewController:self
     handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
         if (error)  {
             NSLog(@"Process error");

         }
         else if (result.isCancelled)
         {
             NSLog(@"Cancelled");
         }
         else {
             if ([FBSDKAccessToken currentAccessToken]) {
                 [[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:@{@"fields": @"email, name"}]
                  startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
                      if (!error) {
                          NSLog(@"fetched user:%@", result);

                      }
                  }];
             }
         }
     }];

只需单击FBSDKLoginBehaviorNative,它将引导您进入FacebookLoginManager.h

正确阅读并理解。

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 Attempts 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,
};