问题
I'm trying to implement google+ and facebook sign ins in the same app. I followed the instructions by Parse and Google and I first successfully implemented Facebook login. Then I started to follow the google instructions. After doing that, now I'm having these 2 functions in my AppDelegate.swift file:
For google:
func application(application: UIApplication,
openURL url: NSURL, options options: [String: AnyObject]) -> Bool {
return GIDSignIn.sharedInstance().handleURL(url,
sourceApplication: options[UIApplicationOpenURLOptionsSourceApplicationKey],
annotation: options[UIApplicationOpenURLOptionsAnnotationKey])
}
For facebook:
func application(application: UIApplication,
openURL url: NSURL,
sourceApplication: String?,
annotation: AnyObject?) -> Bool {
return FBSDKApplicationDelegate.sharedInstance().application(application,
openURL: url,
sourceApplication: sourceApplication,
annotation: annotation)
}
Do I need to combine these 2 blocks of code into 1 as seen in some posts such as
Google SignIn SFSafariViewController/WebView redirects to Google.com after accepting permissions
or they can stay like that in 2 different blocks? Thanks
回答1:
You need to combine them. The simplest way is to use an || on the return statement. Try this:
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)
}
回答2:
You would be well served to use Google Identity Toolkit (now repackaged as Firebase) to achieve this and allow extensions to other IDP's as well
来源:https://stackoverflow.com/questions/34125280/ios-facebook-and-google-login-at-the-same-time