ios – 在Facebook浏览器登录重定向到应用程序后,Handler不会被调用

我在我的应用程序中使用Facebook SDK v4.8.0 for iOS登录Facebook. (iPhone OS版本9.3)

以下是一些相关的集成代码:

AppDelegate.swift

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    return true
}

func applicationDidBecomeActive(application: UIApplication) {
    FBSDKAppEvents.activateApp()
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {    
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

func application(application: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool {
        return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url,
                                                                     sourceApplication: "UIApplicationOpenURLOptionsSourceApplicationKey",
                                                                     annotation: "UIApplicationOpenURLOptionsAnnotationKey")
}

Login.Swift

@IBAction func btnFacebook(sender: UIButton) {

    self.loginToFacebookWithSuccess({ (response) -> Void in
        print("Success")
    }) { (error) -> Void in
        print("failure")
    }

func loginToFacebookWithSuccess(successBlock: () -> (), andFailure failureBlock: (NSError?) -> ()) {

    let fbLoginManager : FBSDKLoginManager = FBSDKLoginManager()
    fbLoginManager.loginBehavior = .SystemAccount

    FBSDKLoginManager().logInWithReadPermissions(["public_profile", "email", "user_friends"], fromViewController: self, handler: { (result:FBSDKLoginManagerLoginResult!, error:NSError!) -> Void in

        if error != nil {
            print("error")
        } else if result.isCancelled {
            print("cancelled")
        } else {
            print("worked fine") // get Facebook user data here
        }
    })
}

当用户未在设备中配置Facebook帐户时,应用程序将转到浏览器并提供Facebook登录UI.一旦用户完成登录,浏览器就会重定向到应用程序.直到这一点,一切正常.

问题

当浏览器将用户重定向到App时,没有任何反应. (不会调用成功或失败的处理程序).如果用户在浏览器中点击“完成”,则会在日志中打印“已取消”.但是,对于“取消”或“好”(或说“继续作为用户名”)重定向后没有任何反应.

任何线索?

如果我错过了任何信息,请告诉我.

最佳答案
我认为您的开放网址方法需要进行以下更改:

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

    let isFBURL = ((url.scheme?.hasPrefix("fb\(FBSDKSettings.appID()!)"))! && url.host == "authorize")

    if  isFBURL == true {

        return FBSDKApplicationDelegate.sharedInstance().application(application, open: url,
                                                                     sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
                                                                     annotation: options[UIApplicationOpenURLOptionsKey.annotation] as? String)
    }
}

如果有效,请告诉我.

转载注明原文:ios – 在Facebook浏览器登录重定向到应用程序后,Handler不会被调用 - 代码日志