我使用的是Google Sign-In 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`
我的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)
}
请给我解决方案。为什么会崩溃?
答案 0 :(得分:37)
正如错误清楚地说明,您的应用程序缺少对网址方案的支持。
将以下方案添加到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>
检查此网址是否为您的ID =&gt; https://developers.google.com/identity/sign-in/ios/start-integrating
您的info.plist应该如下 - &gt;
答案 1 :(得分:21)
您必须为项目添加URL方案
答案 2 :(得分:3)
对于那些由于google_sign_in
软件包在iOS设备上崩溃而从Flutter来到这里的人-我已经介绍过此问题here
长话短说:尝试显式设置属性hostedDomain
和clientId
。
GoogleSignIn googleSignIn = GoogleSignIn(
scopes: ['email', 'profile'],
hostedDomain: "",
clientId: "",);
答案 3 :(得分:2)
再次检查:
在AppDelegate
中反向 DNS:
GIDSignIn.sharedInstance().clientID = "536164374389-ivga9a9at2g31nfmhpvdyhc98yf6afnr.apps.googleusercontent.com"
在Info.plist
中直接 DNS:
<string>com.googleusercontent.apps.536164374389-ivga9a9at2g31nfmhpvdyhc98yf6afnr</string>
答案 4 :(得分:0)
您必须添加反向的客户端ID,而不是普通的客户端ID。
答案 5 :(得分:0)
答案 6 :(得分:0)
我也已经浪费了超过4个小时来存储类似的日志(我正在使用VScode来开发iOS应用)
对我来说,主要问题是GoogleService-Info.plist不在Runner目录中。
我必须通过右键单击Runner并添加文件按钮,通过XCODE添加GoogleService-Info.plist。
总体而言,我了解到Flutter调试器(或vscode插件?)没有提供有关该错误的完整信息。
请查看此以获取更多信息 https://github.com/flutter/flutter/issues/22536
Check this image for what the 'Right clicking Runner and than add files'
答案 7 :(得分:0)
在GoogleSignIn SDK 5.0中
添加代码
GIDSignIn.sharedInstance()。delegate =自我
GIDSignIn.sharedInstance()。presentingViewController = self
代替此代码
GIDSignIn.sharedInstance()。delegate =自我
GIDSignIn.sharedInstance()。uiDelegate =自我
答案 8 :(得分:0)
我遇到了类似的问题。如果其他方法对您没有帮助,请尝试此方法。
由于经常将Google和Facebook登录在一起,因此您有可能同时实现它们。
最新的Google Dev文档使您可以使用“项目目标”>“信息”>“ URL类型”来实现URL方案。尽管Facebook文档会告诉您在info.plist
文件中实现url方案。在.plist文件中实现时,其他URL方案将被替换。因此,请在“项目”的“目标”部分中实施所有URL方案。
Your project target will look like this
希望有人发现这有帮助