我正在尝试将 fb 和新的 google 登录集成到一个应用程序中,但遇到某些问题,有人可以帮忙吗。
其实我在 AppDelegate.m 里写过这个。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
NSError* configureError;
[[GGLContext sharedInstance] configureWithError: &configureError];
NSAssert(!configureError, @"Error configuring Google services: %@", configureError);
[GIDSignIn sharedInstance].delegate = self;
return [[FBSDKApplicationDelegate sharedInstance] application:application
didFinishLaunchingWithOptions:launchOptions];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
return [[FBSDKApplicationDelegate sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation] && [[GIDSignIn sharedInstance] handleURL:url
sourceApplication:sourceApplication
annotation:annotation];
}
然后我在另一个类中创建谷歌登录按钮
- (void)viewDidLoad {
[super viewDidLoad];
fbLogingButton = [[FBSDKLoginButton alloc]init];
fbLogingButton.delegate = self;
fbLogingButton.center = self.view.center;
[self.view addSubview:fbLogingButton];
fbLogingButton.readPermissions =
@[@"public_profile", @"email", @"user_friends"];
googleSignInButton = [[GIDSignInButton alloc]initWithFrame:CGRectMake(120, 370,50, 150)];
[self.view addSubview:googleSignInButton];
[GIDSignIn sharedInstance].uiDelegate = self;
// Do any additional setup after loading the view, typically from a nib.
}
但是应用在启动时崩溃了
[[GGLContext sharedInstance] configureWithError: &configureError];
如果我评论说如果我点击登录按钮它会崩溃
崩溃日志说
2015-09-07 17:10:38.272 DemoAppSep[62471:3858047] Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|' First throw call stack: ( 0 CoreFoundation 0x00000001042fbc65 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000103f92bb7 objc_exception_throw + 45 2 CoreFoundation
0x00000001042fbb9d +[NSException raise:format:] + 205 3 DemoAppSep 0x00000001017581ef -[GIDSignIn assertValidParameters] + 77 4
DemoAppSep 0x000000010175a589 -[GIDSignIn signInWithOptions:] + 52 5 DemoAppSep
0x000000010175e5c6 -[GIDSignInButton pressed] + 331 6 UIKit
0x00000001046f6da2 -[UIApplication sendAction:to:from:forEvent:] +
最佳答案
将此用于 FaceBook https://developers.facebook.com/docs/ios/getting-started
将此用于 GooglePlus https://developers.google.com/+/mobile/ios/getting-started
必须遵循所有步骤
最后在 AppDelegate.m 中
- (BOOL) application:(UIApplication *) application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
BOOL wasHandled=false;;
if ([url.scheme hasPrefix:@"fb"]) {
wasHandled = [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
//Facebook callback
}
else //Google Plus callback
{
wasHandled= [GPPURLHandler handleURL:url sourceApplication:sourceApplication annotation:annotation];
}
NSLog ( @"application openURL");
NSLog ( @"URL = %@", url);
NSLog ( @"Application = %@", sourceApplication);
return wasHandled;
}
它会起作用的。谢谢
关于ios - Google 和 Facebook 在同一个应用程序中登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32438023/