0

我正在使用最新版本的 ParseFacebookUtils,它使用 safari 来登录用户。该过程按预期工作,它要求您在 Safari 中访问您的公共个人资料并返回应用程序。奇怪的行为是,当登录请求返回到应用程序时,块内的代码永远不会执行。

只有当我再次按下登录按钮或者我将登录行为设置为基于 Web 的情况下,它才会执行,其中 Web 视图显示在应用程序中。但这不是最好的,因为用户必须登录并且他们可能忘记了他们的详细信息。下面是我用来登录用户的代码。

   PFFacebookUtils.logIn(withPermissions: ["public_profile"]) { user, error in

            if let user = user {
                if user.isNew {
                    print("User signed up and logged in through Facebook!")
                } else {
                    print("User logged in through Facebook!")
                }
            } else {
                print("Uh oh. The user cancelled the Facebook login.")
            }
        }

这是我用于初始化和处理 url 的应用程序委托中的代码。

import UIKit
import Parse
import ParseFacebookUtils

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

        Parse.initialize(with: ParseConfig.configuration)
        PFFacebookUtils.initializeFacebook()

        // Configure an anon user on startup
        PFUser.enableAutomaticUser()
        PFUser.current()?.saveInBackground()


        return true
    }

    func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {

        return FBAppCall.handleOpen(url, sourceApplication: UIApplicationOpenURLOptionsKey.sourceApplication.rawValue)
    }
}
4

0 回答 0