尝试调用 canOpenURL 在 iOS 9 上的 Google 登录崩溃
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31506865/
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
Google Sign-In crashes on iOS 9 attempting to call canOpenURL
提问by
While testing Google Sign-In 2.1.0 on the iOS 9 SDK, invoking GIDSignIn.sharedInstance().signInSilently()
ends up crashing on an internal Google Sign-In SDK call to canOpenURL
.
在 iOS 9 SDK 上测试 Google Sign-In 2.1.0 时,调用GIDSignIn.sharedInstance().signInSilently()
最终会在对canOpenURL
.
-canOpenURL: failed for URL: "com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz://a" - error: "This app is not allowed to query for scheme com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz"
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Your app must support the following URL schemes: com.example.foo, com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz'
-canOpenURL: failed for URL: "com-google-gidconsent-google://" - error: "This app is not allowed to query for scheme com-google-gidconsent-google"
-canOpenURL: failed for URL: "com-google-gidconsent-youtube://" - error: "This app is not allowed to query for scheme com-google-gidconsent-youtube"
-canOpenURL: failed for URL: "com-google-gidconsent://" - error: "This app is not allowed to query for scheme com-google-gidconsent"
-canOpenURL: failed for URL: "com.google.gppconsent.2.4.1://" - error: "This app is not allowed to query for scheme com.google.gppconsent.2.4.1"
-canOpenURL: failed for URL: "com.google.gppconsent.2.4.0://" - error: "This app is not allowed to query for scheme com.google.gppconsent.2.4.0"
-canOpenURL: failed for URL: "googlechrome:" - error: "This app is not allowed to query for scheme googlechrome"
-canOpenURL: failed for URL: "googlechrome-x-callback:" - error: "This app is not allowed to query for scheme googlechrome-x-callback"
-canOpenURL: failed for URL: "googlechrome-x-callback:" - error: "This app is not allowed to query for scheme googlechrome-x-callback"
-canOpenURL: failed for URL: "googlechrome:" - error: "This app is not allowed to query for scheme googlechrome"
回答by
iOS 9 has introduced new changes to canOpenURL
requiring the application to whitelist all the schemes it needs to query.
iOS 9 引入了新的变化,canOpenURL
要求应用程序将它需要查询的所有方案列入白名单。
This post on Quick Take on iOS 9 URL Scheme Changesexplains why.
这篇关于 iOS 9 URL Scheme Changes 的 Quick Take文章解释了原因。
At a minimum you need to whitelist you own application's identifier and your Google OAuth apps id in Info.plist
under LSApplicationQueriesSchemes
. You can also whitelist the other schemes Google Sign-In queries to silence the other warnings.
您至少需要白名单,你自己的应用程序的标识和您的谷歌的OAuth应用程式中并编号Info.plist
下LSApplicationQueriesSchemes
。您还可以将其他方案的 Google 登录查询列入白名单以消除其他警告。
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com.example.foo</string>
<string>com.googleusercontent.apps.1234567890-abcdefghijklmnopqrstuvwxyz</string>
<string>com-google-gidconsent-google</string>
<string>com-google-gidconsent-youtube</string>
<string>com-google-gidconsent</string>
<string>com.google.gppconsent.2.4.1</string>
<string>com.google.gppconsent.2.4.0</string>
<string>googlechrome</string>
<string>googlechrome-x-callback</string>
</array>
回答by emem
Just follow the steps in: https://developers.google.com/identity/sign-in/ios/start-integrating#add_url_schemes_to_your_project(including adding the schemes) and it should be working fine.
只需按照以下步骤操作:https: //developers.google.com/identity/sign-in/ios/start-integrating#add_url_schemes_to_your_project(包括添加方案),它应该可以正常工作。
And, as requested by comments below, I'll emphasise that the problem probably occurred by not adding the URL schemes as described in the link above.
并且,根据下面评论的要求,我将强调该问题可能是由于未添加上述链接中所述的 URL 方案而发生的。
Quoting from the link above:
引用上面的链接:
Google Sign-in requires two custom URL Schemes to be added to your project.
To add the custom schemes:
- Open your project configuration: double-click the project name in the left tree view. Select your app from the TARGETS section, then select the Info tab, and expand the URL Types section.
- Click the + button, and add a URL scheme for your reversed client ID. To find this value, open the GoogleService-Info.plist configuration file, and look for the REVERSED_CLIENT_ID key. Copy the value of that key, and paste it into the URL Schemes box on the configuration page. Leave the other fields blank.
- Click the + button, and add a second URL scheme. This one is the same as your app's bundle ID. For example, if your bundle ID is com.example.app, type that value into the URL Schemes box. You can find your app's bundle ID in the General tab of the project configuration (Identity > Bundle Identifier).
Google Sign-in 需要将两个自定义 URL Scheme 添加到您的项目中。
添加自定义方案:
- 打开您的项目配置:双击左侧树视图中的项目名称。从 TARGETS 部分选择您的应用,然后选择 Info 选项卡,并展开 URL Types 部分。
- 单击 + 按钮,然后为反向客户端 ID 添加 URL 方案。要查找此值,请打开 GoogleService-Info.plist 配置文件,并查找 REVERSED_CLIENT_ID 键。复制该键的值,并将其粘贴到配置页面上的 URL Schemes 框中。将其他字段留空。
- 单击 + 按钮,然后添加第二个 URL 方案。这与您的应用程序包 ID 相同。例如,如果您的包 ID 是 com.example.app,请在 URL Schemes 框中键入该值。您可以在项目配置的 General 选项卡(Identity > Bundle Identifier)中找到您的应用程序包 ID。
回答by Sourabh Sharma
Updated for XCode 7.0 and Google plus Sdk 1.7.1
为 XCode 7.0 和 Google plus Sdk 1.7.1 更新
<key>LSApplicationQueriesSchemes</key>
<array>
<string>com-google-gidconsent-google</string>
<string>com-google-gidconsent-youtube</string>
<string>com-google-gidconsent</string>
<string>com.google.gppconsent.2.4.1</string>
<string>com.google.gppconsent.2.4.0</string>
<string>googlechrome</string>
<string>googlechrome-x-callback</string>
<string>hasgplus4</string>
<string>com.google.gppconsent.2.3.0</string>
<string>com.google.gppconsent.2.2.0</string>
<string>com.google.gppconsent</string>
</array>
回答by Todd Kerpelman
Josh's answer is correct for earlier versions of the Google Sign-in library. However, it looks like starting with version 2.2.0, this step is no longer necessary (hooray!).
Josh 的回答对于早期版本的 Google 登录库是正确的。但是,看起来从 2.2.0 版本开始,这一步就不再需要了(万岁!)。
So if you're still encountering this issue, my advice might be to update your Google Sign-In library.
因此,如果您仍然遇到此问题,我的建议可能是更新您的 Google 登录库。
回答by Isuru
After adding the GoogleService-Info.plistto my project, I added the following to the Info.plistfile and the errors went away.
将GoogleService-Info.plist添加到我的项目后,我将以下内容添加到Info.plist文件中,错误消失了。
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>fb1413410832299369</string>
<string>com.my.app</string> <!-- My app bundle ID -->
<string>com.googleusercontent.apps.1111111111-6jcxxxxxxxikgnso524xxxxxxxx5o9</string> <!-- Reverssed client ID -->
</array>
</dict>
</array>
回答by Chris
For me, putting the LSApplicationQueriesSchemes
in the info.plist didn't work, but putting it under 'Project > Target > Info > URL Types' did the trick for me.
对我来说,把它LSApplicationQueriesSchemes
放在 info.plist 中没有用,但把它放在“项目>目标>信息>URL类型”下对我有用。
回答by Aldo Ernesto Arias Figueroa
Add your com.googleusercontent.apps. into URL Types
添加您的 com.googleusercontent.apps。进入 URL 类型
Click into the Main Project -> Info -> URL Types
点击进入 Main Project -> Info -> URL Types