在iOS中集成Google和Facebook登录 - AppDelegate openURL [英] Integrating Google and Facebook login in iOS - AppDelegate openURL
本文介绍了在iOS中集成Google和Facebook登录 - AppDelegate openURL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试将Facebook和谷歌登录集成到我的应用程序中,但遇到问题:两者都需要将以下内容添加到Appdelegate中的openURL方法中:
I'm trying to integrate facebook and google login into my app but having a problem: Both require the following to be added into the openURL method in the Appdelegate:
return [GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation]];
return [FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
]]
无论如何都要让这两者正常合作。我看过网上但答案很模糊,未能提供很好的解释
Is there anyway of having these both work together properly. I've looked online but the answers are quite vague and fail to provide a good explanation
解决方案
为我添加了以下功能(从iOS 9开始):
Added the following which did the trick for me (as of iOS 9):
return [[GIDSignIn sharedInstance] handleURL:url sourceApplication:sourceApplication annotation:annotation] || [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation ];
推荐答案
使用以下代码......
use following code...
- (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplicationannotation:(id)annotation
{
if ([FBAppCall handleOpenURL:url sourceApplication:sourceApplication])
return [FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation
]];
else
return [GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation]];
}
另一个答案..
- (BOOL)application:(UIApplication *)applicationopenURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplicationannotation:(id)annotation
{
NSString *stringURL = [ url absoluteString];
if([stringURL containsString:@"fb"])
{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
else
{
return [GPPURLHandler handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
}
这篇关于在iOS中集成Google和Facebook登录 - AppDelegate openURL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文