gpt4 book ai didi

ios - 如何实现 iOS 的 Facebook 原生登录?

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:05:21 26 4
gpt4 key购买 nike

为我的应用程序支持 Facebook 登录的最佳做法是什么?

我正在查看现有的与 Facebook 集成的应用程序。以 Pinterest 为例,即使设备上没有安装 Facebook 应用程序,该应用程序也使用 iOS 原生登录。我也想实现这样的逻辑流程。

看着:

Get if my app is authorized to use facebook [iOS 6, FB SDK 3.2]

https://developers.facebook.com/docs/ios/

https://developer.apple.com/documentation/social/slcomposeviewcontroller

https://developer.apple.com/documentation/accounts

我不清楚如何实现回退流程,应用会执行以下操作:

如果可以使用设备登录,请使用它。如果不是,则回退到 Facebook 应用程序登录,如果不是回退到 Facebook Safari 登录。

最佳答案

您可以在打开 session 时执行此身份验证,如下所示。此枚举 FBSessionLoginBehaviorUseSystemAccountIfPresent 将执行如下步骤

  1. 尝试在设置应用程序中访问 Facebook 帐户
  2. 如果失败 #1,如果安装了 Facebook 原生应用,则转向快速应用切换
  3. 如果 #2 失败,它将切换到 safari。

    [FBSession.activeSession openWithBehavior:FBSessionLoginBehaviorUseSystemAccountIfPresent
    completionHandler:^(FBSession *session,
    FBSessionState状态,
    NSError *错误){
    //你的代码。
    }];

枚举常量清楚地说明了登录流程,我们可以随意选择其中的任何一个。

@discussion Facebook Login authorizes the application to act on behalf of the user, using the user's Facebook account. Usually a Facebook Login will rely on an account maintained outside of the application, by the native Facebook application, the browser, or perhaps the device itself. This avoids the need for a user to enter their username and password directly, and provides the most secure and lowest friction way for a user to authorize the application to interact with Facebook. If a Facebook Login is not possible, a fallback Facebook Login may be attempted, where the user is prompted to enter their credentials in a web-view hosted directly by the application.

The FBSessionLoginBehavior enum specifies whether to allow fallback, disallow fallback, or force fallback login behavior. Most applications will use the default, which attempts a normal Facebook Login, and only falls back if needed. In rare cases, it may be preferable to disallow fallback Facebook Login completely, or to force a fallback login. */

typedef enum {
/*! Attempt Facebook Login, ask user for credentials if necessary */
FBSessionLoginBehaviorWithFallbackToWebView = 0,
/*! Attempt Facebook Login, no direct request for credentials will be made */
FBSessionLoginBehaviorWithNoFallbackToWebView = 1,
/*! Only attempt WebView Login; ask user for credentials */
FBSessionLoginBehaviorForcingWebView = 2,
/*! Attempt Facebook Login, prefering system account and falling back to fast app switch if necessary */
FBSessionLoginBehaviorUseSystemAccountIfPresent = 3,
} FBSessionLoginBehavior;

注意:查看文档以了解如何使用 FB 应用程序进行应用程序切换。那么只有这个枚举会按预期工作。

关于ios - 如何实现 iOS 的 Facebook 原生登录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23606206/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com