ios - Google 和 Facebook 在同一个应用程序中登录

标签 ios facebook integration google-signin

我正在尝试将 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/

相关文章:

ios - AVFoundation:返回第一屏幕时防止背景音乐播放两次

android - Facebook SDK 的分享对话框会在应用加载后立即出现

单页应用程序的javascript集成测试

css - 集成时避免使用预定义的 css div

MySQL选择最高用户最高排名组双胞胎

ios - Vidyo 应用程序在 Swift 上崩溃

iOS 9.0 Xcode 8.3.3 MfiBtPrinterConnection.h 传输蓝牙 maxLength Zebra ZQ520

ios - 寻找每帧更新实例属性的方法

python - 使用具有自签名证书的 django-sslserver 在本地主机上进行的 django facebook 应用程序测试被拒绝

php - 从模型函数中排序数组列表