ios 单击 GoogleSignIn 按钮时应用程序崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42197729/
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
App getting crash when click on GoogleSignIn button
提问by Vikas
I am using Google Sign-In SDK 4.0.1. When I press googleSignInButton then app will be crash. And gave below error, how to fix this:
我正在使用 Google 登录 SDK 4.0.1。当我按下 googleSignInButton 时,应用程序将崩溃。并给出了以下错误,如何解决这个问题:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app is missing support for the following URL schemes: com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6'
*** First throw call stack:
(
0 CoreFoundation 0x0000000101ac0d4b __exceptionPreprocess + 171
1 libobjc.A.dylib 0x000000010110121e objc_exception_throw + 48
2 CoreFoundation 0x0000000101b2a2b5 +[NSException raise:format:] + 197
3 xxxxx 0x000000010084b3cb -[GIDSignIn signInWithOptions:] + 246
4 xxxxx 0x000000010084efc2 -[GIDSignInButton pressed] + 242
5 UIKit 0x00000001028f78bc -[UIApplication sendAction:to:from:forEvent:] + 83
6 UIKit 0x0000000102a7dc38 -[UIControl sendAction:to:forEvent:] + 67
7 UIKit 0x0000000102a7df51 -[UIControl _sendActionsForEvents:withEvent:] + 444
8 UIKit 0x0000000102a7ce4d -[UIControl touchesEnded:withEvent:] + 668
9 UIKit 0x0000000102965545 -[UIWindow _sendTouchesForEvent:] + 2747
10 UIKit 0x0000000102966c33 -[UIWindow sendEvent:] + 4011
11 UIKit 0x00000001029139ab -[UIApplication sendEvent:] + 371
12 UIKit 0x000000010310072d __dispatchPreprocessedEventFromEventQueue + 3248
13 UIKit 0x00000001030f9463 __handleEventQueue + 4879
14 CoreFoundation 0x0000000101a65761 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
15 CoreFoundation 0x0000000101a4a98c __CFRunLoopDoSources0 + 556
16 CoreFoundation 0x0000000101a49e76 __CFRunLoopRun + 918
17 CoreFoundation 0x0000000101a49884 CFRunLoopRunSpecific + 420
18 GraphicsServices 0x00000001074cfa6f GSEventRunModal + 161
19 UIKit 0x00000001028f5c68 UIApplicationMain + 159
20 xxxxxxxx 0x00000001007c449f main + 111
21 libdyld.dylib 0x0000000104d5368d start + 1
22 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException`
My AppDelegate.Swift is
我的 AppDelegate.Swift 是
class AppDelegate: UIResponder, UIApplicationDelegate, GIDSignInDelegate {
public func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {
if (error == nil) {
let userId:NSString = user.userID as NSString; // For client-side use only!
let idToken: NSString = user.authentication.idToken as NSString; // Safe to send to the server
let fullName:NSString = user.profile.name as NSString;
let givenName:NSString = user.profile.givenName as NSString;
let familyName:NSString = user.profile.familyName as NSString;
let email:NSString = user.profile.email as NSString;
print(userId)
print(userId,idToken,fullName,givenName,familyName,email)
}
else {
print("\(error.localizedDescription)")
}
}
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let kclientID:NSString = "107731993306-xxxxxxxxxxxxxxxxx.apps.googleusercontent.com"
GIDSignIn.sharedInstance().clientID = kclientID as String!
GIDSignIn.sharedInstance().delegate = self
return true
}
func application(application: UIApplication,
openURL url: NSURL, options: [String: AnyObject], annotation:Any, sourceApplication:String?) -> Bool {
return GIDSignIn.sharedInstance().handle(url as URL!, sourceApplication:sourceApplication, annotation: annotation)
}
Please give me the solution. Why it is crashed?
请给我解决方案。为什么会崩溃?
回答by Kakshil Shah
As the error clearly says, your app is missing support for the url schemes.
正如错误明确指出的那样,您的应用程序缺少对 url 方案的支持。
Add the following schemes to your info.plist
将以下方案添加到您的 info.plist
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>***Your bundle ID***</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6</string>
</array>
</dict>
<dict>
<key>CFBundleTypeRole</key>
<string>Editor</string>
<key>CFBundleURLSchemes</key>
<array>
<string>***Something here***</string>
</array>
</dict>
</array>
Check this url for your id => https://developers.google.com/identity/sign-in/ios/start-integrating
检查此 url 以获取您的 id => https://developers.google.com/identity/sign-in/ios/start-integrating
Your info.plist should look like ->
你的 info.plist 应该看起来像 ->
回答by Hyman
You have to add a URL scheme to your project
你必须在你的项目中添加一个 URL 方案
- Open your project configuration: double-click the project name in the left tree view. Select your app from the TARGETSsection, then select the Info tab, and expand the URL Types section
- Click the + button, and add a URL scheme -com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6
- 打开您的项目配置:双击左侧树视图中的项目名称。从TARGETS部分选择您的应用,然后选择 Info 选项卡,并展开URL Types 部分
- 单击 + 按钮,并添加一个 URL 方案 - com.googleusercontent.apps.107731993306-6s44u18onibp6gi0ddj94si1aifshhg6
回答by Argus
I got that crash too. But selected answer did not help me.
我也遇到了那个崩溃。但是选择的答案对我没有帮助。
Double check that:
仔细检查:
In AppDelegate
straightDNS:
在AppDelegate
直接DNS 中:
GIDSignIn.sharedInstance().clientID = "536164374389-ivga9a9at2g31nfmhpvdyhc98yf6afnr.apps.googleusercontent.com"
In Info.plist
reverseDNS:
在Info.plist
反向DNS 中:
<string>com.googleusercontent.apps.536164374389-ivga9a9at2g31nfmhpvdyhc98yf6afnr</string>
回答by Kirill Karmazin
For those who came here from Flutter because of the crash of google_sign_in
package on iOS devices - I've already covered this issue here
对于那些因为google_sign_in
iOS 设备上的包崩溃而从 Flutter 来到这里的人- 我已经在这里讨论了这个问题
Long story short: try to explicitly set properties hostedDomain
and clientId
.
长话短说:尝试显式设置属性hostedDomain
和clientId
.
GoogleSignIn googleSignIn = GoogleSignIn(
scopes: ['email', 'profile'],
hostedDomain: "",
clientId: "",);
回答by Rahul Patel
in GoogleSignIn SDK 5.0
在 GoogleSignIn SDK 5.0 中
add code
添加代码
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().presentingViewController = self
GIDSignIn.sharedInstance().presentingViewController = self
instead of this code
而不是这个代码
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().delegate = self
GIDSignIn.sharedInstance().uiDelegate = self
GIDSignIn.sharedInstance().uiDelegate = self
回答by YellowHalfStone
I've also waste over 4hours for similar logs (I'm developing ios app by flutter with VScode)
我也为类似的日志浪费了 4 多个小时(我正在使用 VScode 通过 flutter 开发 ios 应用程序)
For me the main problem was GoogleService-Info.plist was not truly in the Runner directory.
对我来说,主要问题是 GoogleService-Info.plist 并不真正在 Runner 目录中。
I MUST had to add the GoogleService-Info.plist by XCODE, by right clicking Runner and add files button.
我必须通过 XCODE 添加 GoogleService-Info.plist,右键单击 Runner 并添加文件按钮。
For overall, I learn that The flutter debugger(or vscode plugin?) does not give full information about the error.
总的来说,我了解到 Flutter 调试器(或 vscode 插件?)没有提供有关错误的完整信息。
Please look this for more information https://github.com/flutter/flutter/issues/22536
请查看此以获取更多信息 https://github.com/flutter/flutter/issues/22536
Check this image for what the 'Right clicking Runner and than add files'
回答by Divyesh Vasoya
you have to add reversed client id instead of normal one.
您必须添加反向客户端 ID 而不是正常的客户端 ID。