xcode 您必须指定 |clientID| 用于 |GIDSignIn| 尝试使用 Google 登录时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/39731783/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
You must specify |clientID| for |GIDSignIn| error when trying to sign in with Google
提问by Daniel Que
Google sign in was working fine with Xcode 7. After updating to Xcode 8, I started getting the error: Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|'
. I have a GoogleService-Info.plist file with my CLIENT_ID.
Google 登录在 Xcode 7 上运行良好。更新到 Xcode 8 后,我开始收到错误消息:Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'You must specify |clientID| for |GIDSignIn|'
. 我有一个带有 CLIENT_ID 的 GoogleService-Info.plist 文件。
I was able to fix it by adding the following line:
我能够通过添加以下行来修复它:
GIDSignIn.sharedInstance().clientID = "<CLIENT_ID>"
It seems the CLIENT_ID isn't being fetched from GoogleService-Info.plist. I've made sure it's in the Copy Bundle Resources.
似乎没有从 GoogleService-Info.plist 获取 CLIENT_ID。我已经确定它在 Copy Bundle Resources 中。
I shouldn't have to specify the client id in the code. How can I fix it to get the information from the GoogleService-Info.plist file?
我不应该在代码中指定客户端 ID。如何修复它以从 GoogleService-Info.plist 文件中获取信息?
回答by Donal
You can do it this way.
你可以这样做。
Swift:
迅速:
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
Objective-C:
目标-C:
GIDSignIn.sharedInstance.clientID = FIRApp.defaultApp.options.clientID;
回答by Steven
Please make sure you have these code place in sequence.
请确保您按顺序放置了这些代码。
FirebaseApp.configure()
GIDSignIn.sharedInstance().clientID = FirebaseApp.app()?.options.clientID
GIDSignIn.sharedInstance().delegate = self
FirebaseApp.app()?.options.clientID
will only able to get data from GoogleService-Info.plist after FirebaseApp.configure()
is called.
FirebaseApp.app()?.options.clientID
FirebaseApp.configure()
调用后只能从 GoogleService-Info.plist 获取数据。
回答by Zeeshan Tufail
I had the same problem. Actually GoogleServices-Info.plist
had been updated in my case.
I re-downloaded GoogleServices-Info.plist
and updated it with the older one which fixed the issue for me.
我有同样的问题。实际上GoogleServices-Info.plist
已经在我的情况下更新了。我重新下载GoogleServices-Info.plist
并用旧的更新了它,为我解决了这个问题。
回答by WINSergey
I solve it with adding forgotten code to AppDelegate class:
我通过向 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
回答by user2451436
swift 3 in AppDelegate add:
在 AppDelegate 中 swift 3 添加:
var configureError: NSError?
GGLContext.sharedInstance().configureWithError(&configureError)
assert(configureError == nil, "Error configuring Google services: \
(String(describing: configureError))")
回答by The Senator
If you've arrived here using Google SignIn from Xamarin in iOS then you seem to be required to set the Client Id specifically on the shared SignIn instance in order for the remainder of the process to work. I have a class for managing the callbacks for iOS Google Authentication within which I do the following code:
如果您在 iOS 中使用来自 Xamarin 的 Google SignIn 到达这里,那么您似乎需要在共享 SignIn 实例上专门设置客户端 ID,以便流程的其余部分工作。我有一个用于管理 iOS Google 身份验证回调的类,我在其中执行以下代码:
SignIn.SharedInstance.ClientID = "[Client Id Here].apps.googleusercontent.com";
SignIn.SharedInstance.Delegate = this;
SignIn.SharedInstance.UIDelegate = this;
SignIn.SharedInstance.SignInUser();
I'd recommend obviously putting this client id in a configuration setting somewhere although I had assumed it would just pick up the client id from the GoogleServices-Info.plist present, but it didn't.
我显然建议将此客户端 ID 放在某处的配置设置中,尽管我认为它只会从存在的 GoogleServices-Info.plist 中获取客户端 ID,但事实并非如此。
I also have the GoogleServices-Info.plist in my 'Resources' folder which is set to BundledResource for build and this I downloaded from the Google Developer Console for my app and then renamed it to 'GoogleServices-Info.plist' from its rather long given name. Finally, also worth looking out for, I set the 'Entitlements.plist' setting specifically in the iOS Bundle Signing page under Custom Entitlements which gets you past the Key Chain error you will inevitably see. Don't forget to 'Enable Keychain' in the Entitlements themselves too.
我的“Resources”文件夹中也有 GoogleServices-Info.plist,该文件夹设置为 BundledResource 以进行构建,我从 Google Developer Console 为我的应用程序下载了该文件夹,然后将其重命名为“GoogleServices-Info.plist”,因为它相当长给定的名称。最后,同样值得一提的是,我在“自定义权利”下的“iOS 捆绑签名”页面中专门设置了“Entitlements.plist”设置,这样您就可以避免不可避免地看到的 Key Chain 错误。不要忘记在权利本身中“启用钥匙串”。
回答by Suraj K Thomas
Despite doing everything my app was crashing on tapping GIDSignInButton
.In my case I moved the code of setting clientID from Appdelegate to where the GIDSignInButtonwas kept (LoginViewController say).
尽管做了所有我的应用程序在点击时崩溃GIDSignInButton
。在我的例子中,我将设置 clientID 的代码从 Appdelegate 移到了GIDSignInButton 的保存位置(LoginViewController 说)。
public override func viewDidLoad() {
super.viewDidLoad()
configureViews()
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().clientID = "Your_ClientID"
}