2016-09-27 25 views
5

Google登錄與Xcode 7一起正常工作。更新到Xcode 8後,我開始收到錯誤:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|'。我有一個帶有我的CLIENT_ID的GoogleService-Info.plist文件。您必須指定| clientID |爲| GIDSignIn |嘗試使用Google登錄時出錯

我能夠通過添加以下行來解決這個問題:

GIDSignIn.sharedInstance().clientID = "<CLIENT_ID>" 

看來CLIENT_ID不是從GoogleService-Info.plist的牽強。我確定它在Copy Bundle Resources中。

enter image description here

我不應該有指定的代碼,客戶端ID。我如何解決它以從GoogleService-Info.plist文件中獲取信息?

回答

1

我有同樣的問題。其實GoogleServices-Info.plist已更新在我的情況。 我重新下載了GoogleServices-Info.plist,並更新了舊版本,它爲我解決了這個問題。

0

我忘記添加代碼AppDelegate類解決這個問題:

#import "AppDelegate.h" 
#import <Google/SignIn.h>  

@interface AppDelegate()<GIDSignInDelegate> 

@end 

@implementation AppDelegate 

#pragma mark - UIApplicationDelegate 

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 
    //Google sign-in setup 
    NSError* configureError; 
    [[GGLContext sharedInstance] configureWithError: &configureError]; 
    if (configureError) { 
     NSLog(@"Error configuring Google services: %@", configureError.localizedDescription); 
    } 

    [GIDSignIn sharedInstance].delegate = self; 

    return YES; 
} 


#pragma mark - GIDSignInDelegate 

- (void)signIn:(GIDSignIn *)signIn didSignInForUser:(GIDGoogleUser *)user withError:(NSError *)error { 
    //add your code here 
} 

- (void)signIn:(GIDSignIn *)signIn didDisconnectWithUser:(GIDGoogleUser *)user withError:(NSError *)error { 
    //add your code here 
} 

@end 
6

你可以這樣來做。

GIDSignIn.sharedInstance().clientID = FIRApp.defaultApp()?.options.clientID 
+0

在FirebaseApp.configure()後面將這個東西寫在AppDelegate文件中。 – hussain

0

SWIFT 3 在AppDelegate中添加:

var configureError: NSError? 
GGLContext.sharedInstance().configureWithError(&configureError) 
assert(configureError == nil, "Error configuring Google services: \ 
(String(describing: configureError))") 
0

請確保您有按順序執行這些代碼的地方。

FirebaseApp.configure() 

GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID 
GIDSignIn.sharedInstance().delegate = self 

FirebaseApp.app()?.options.clientID將只能夠FirebaseApp.configure()被調用後從GoogleService-Info.plist中獲取數據。

相關問題