user in my app can login using 2 services : Facebook or Google
everything works fine, however, in the :
- (BOOL)application:(UIApplication *)applicat
The method "application:openURL:sourceApplication:annotation:" is deprecated from iOS9. so now you can use like.
- (BOOL)application:(UIApplication *)app
openURL:(NSURL *)url
options:(NSDictionary *)options {
// For Google sign in SDK
if ([[GIDSignIn sharedInstance] handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]) {
return YES;
// For Facebook SDK
}else if ( [[FBSDKApplicationDelegate sharedInstance] application:app
openURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]){
return YES;
//For Google plus SDK
}else if ([GPPURLHandler handleURL:url
sourceApplication:options[UIApplicationOpenURLOptionsSourceApplicationKey]
annotation:options[UIApplicationOpenURLOptionsAnnotationKey]]){
return YES;
}
return NO;
}
We don't need to Explicitly need to check the URL, below code does it :-
- (BOOL)application: (UIApplication *)application openURL: (NSURL *)url sourceApplication: (NSString *)sourceApplication annotation: (id)annotation
{
if ([GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation]) {
return YES;
}else if([FBAppCall handleOpenURL:url sourceApplication:sourceApplication]){
return YES;
}
return NO;
}
You can Try the following :
if ([[url absoluteString] rangeOfString:@"<Your Google Bundle ID>"].location == NSNotFound)
{
// Call FBAppCall's handleOpenURL:sourceApplication to handle Facebook app responses
BOOL wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
// You can add your app-specific url handling code here if needed
return wasHandled;
}
else
{
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
return YES;
Call the above method in
(BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
in your appDelegeate.m
Basically what this is going to do is examine the url prefix and then call the google+ method if url prefix is ur google+ bundle id , and if not , it'll call the fb method . Hope this helps
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
if( [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation])
{
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
else if([[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation])
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
return NO;
}
You can try this for a Swift 4.2 version:
func application(_ app: UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey : Any] = [:]) -> Bool
{
if (url.scheme?.hasPrefix("fb"))! {
return SDKApplicationDelegate.shared.application(app, open: url, options: options)
}
else
{
return GIDSignIn.sharedInstance().handle(url as URL?, sourceApplication: options[UIApplicationOpenURLOptionsKey.sourceApplication] as? String,
annotation: options[UIApplicationOpenURLOptionsKey.annotation])
}
}
You can just let either Google SDK or Facebook SDK attempt handling and if the SDK does not handle then allow the other SDK to try:
@available(iOS 9.0, *)
private func application(_ application: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any])
-> Bool {
let handled: Bool = SDKApplicationDelegate.shared.application(application, open: url, options: options)
if handled { return handled }
return GIDSignIn.sharedInstance().handle(url,
sourceApplication:options[UIApplication.OpenURLOptionsKey.sourceApplication] as? String,
annotation: [:])
}
//deprecated method iOS 8 and older
func application(_ application: UIApplication, open url: URL, sourceApplication: String?, annotation: Any) -> Bool {
let handled: Bool = SDKApplicationDelegate.shared.application(application,
open: url,
sourceApplication: sourceApplication,
annotation: annotation)
if handled { return handled }
return GIDSignIn.sharedInstance().handle(url,
sourceApplication: sourceApplication,
annotation: annotation)
}