2015-09-07 122 views
1

我試圖在應用程序中集成fb和新谷歌登錄,但面臨某些問題,有人可以幫助。谷歌和Fb登錄在同一個應用程序

其實在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年9月7日17:10:3​​8.272 DemoAppSep [62471:3858047] 終止應用程序由於未捕獲的異常 'NSInvalidArgumentException',理由是:「你 必須指定| clientID的|爲| GIDSignIn |' 第一擲調用堆棧:(0的CoreFoundation 0x00000001042fbc65 __exceptionPreprocess + 165 1 libobjc.A.dylib
0x0000000103f92bb7 objc_exception_throw + 45 2的CoreFoundation
0x00000001042fbb9d + [NSException提高:格式:] + 205 3 DemoAppSep 0x00000001017581ef - [GIDSignIn assertValidParameters ] + 77 4
DemoAppSep 0x000000010175a589 - [GIDSignIn signInWithOptions:] + 52 5 DemoAppSep
0x000000010175e5c6 - [GIDSignInButton按壓] + 331 6的UIKit
0x00000001046f6da2 - [UIApplication的sendAction:爲:從:forEvent:] +

+0

錯誤顯示您尚未爲Google登錄分配clientID:https://developers.google.com/+/mobile/ios/sign-in –

回答

3

使用此爲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; 
} 

末它會 Tkykyou

相關問題