我正在创建一个应用程序,以了解如何在Swift 3中使用Firebase。到目前为止,我已经通过facebook和google实现了身份验证。棘手的部分是AppDelegate中的一个函数:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
// Works with google
return GIDSignIn.sharedInstance().handle(url,sourceApplication: sourceApplication, annotation: annotation)
// Works with facebook
//return FBSDKApplicationDelegate.sharedInstance().application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
}
问题是:如果我在用户登录facebook时评论facebook行,则不会返回应用程序。谷歌也一样。
我正在关注这些指南:
我的问题是,如何使用此功能与许多身份验证提供程序一起正常工作?如果无法做到这一点,那么实施它的正确方法是什么?
感谢您的帮助
答案 0 :(得分:1)
像这样:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool {
let googleSignIn = GIDSignIn.sharedInstance().handle(url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
let facebookSignIn = FBSDKApplicationDelegate.sharedInstance().application(app, open: url, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplicationOpenURLOptionsKey.annotation])
return googleSignIn || facebookSignIn
}
答案 1 :(得分:0)
我找到了答案。 func现在就像这样,适用于Google和Facebook:
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation) {
return true
}
return FBSDKApplicationDelegate.sharedInstance().application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
}