我正在尝试在同一个应用中实施谷歌+和Facebook登录.我按照Parse和Google的指示,首先成功实现了Facebook登录.然后我开始按照谷歌的说明.完成后,现在我在AppDelegate.swift文件中有这两个函数:
对于谷歌:
func application(application: UIApplication, openURL url: NSURL, options options: [String: AnyObject]) -> Bool { return GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey], annotation: options[UIApplicationOpenURLOptionsAnnotationKey]) }
对于Facebook:
func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject?) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation) }
我是否需要将这两个代码块合并为1,如某些帖子中所示
Google SignIn SFSafariViewController/WebView在接受权限后重定向到Google.com
或者他们可以在2个不同的街区保持这样的状态?谢谢
你需要结合它们.最简单的方法是使用|| 在退货声明中.试试这个:
func application(application: UIApplication, openURL url: NSURL, options: [String: AnyObject]) -> Bool { return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as! String, annotation: nil) || GIDSignIn.sharedInstance().handleURL(url, sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey] as? String, annotation: options[UIApplicationOpenURLOptionsAnnotationKey] as? String) }