user in my app can login using 2 services : Facebook or Google
everything works fine, however, in the :
- (BOOL)application:(UIApplication *)applicat
The Swift version for iOS 9.0 and above of the accepted answer could be something like this:
import FacebookCore
[...]
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
if (GIDSignIn.sharedInstance().handle(url)) {
return true
} else if (ApplicationDelegate.shared.application(app, open: url, options: options)) {
return true
}
return false
}
Try to handle the URL with each SDK, the first one that recognizes it ends execution returning true. If no SDK could handle the URL, return false.
I hope it helps someone,
Xavi
This might be the easiest solution,
import GoogleSignIn
import FBSDKCoreKit
func application(_ application: UIApplication,
open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
if GIDSignIn.sharedInstance().handle(url) {
return true
} else if ApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation) {
return true
}
return false
}
@available(iOS 9.0, *)
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any]) -> Bool {
if GIDSignIn.sharedInstance().handle(url) {
return true
} else if ApplicationDelegate.shared.application(app, open: url, sourceApplication: options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String, annotation: options[UIApplication.OpenURLOptionsKey.annotation]
) {
return true
}
return false
}
You'll want to use [[UIApplication sharedApplication] canOpenURL:]
For Swift users, (The idea from user2144179)
Import below frameworks
import Firebase
import GoogleSignIn
import FacebookCore // (FBSDKCore's alternative for swift)
and in your delegate methods
// when your target is under iOS 9.0
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let isFBOpenUrl = SDKApplicationDelegate.shared.application(application, open: url, sourceApplication: sourceApplication, annotation: annotation)
let isGoogleOpenUrl = GIDSignIn.sharedInstance().handle(url, sourceApplication: sourceApplication, annotation: annotation)
if isFBOpenUrl { return true }
if isGoogleOpenUrl { return true }
return false
}
or you can use another 'open url:' method if your target is 9.0+. SDKs include a method for it also.
Firebase Reference : https://firebase.google.com/docs/auth/ios/google-signin
Facebook Reference : https://developers.facebook.com/docs/swift/reference/classes/applicationdelegate.html