在iOS 9中启动Google地图的Url schema会抛出警告并且无法工作

7
以下代码在iOS 8.4及更早版本中运行良好,但从iOS 9.0开始,它开始抛出警告并始终返回“false”。
[[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"comgooglemaps-x-callback://"]]

它显示警告信息,内容为:
-canOpenURL: failed for URL: "comgooglemaps-x-callback://" - error: "This app is not allowed to query for scheme comgooglemaps-x-callback"

有人知道为什么在iOS 9上失败并抛出错误This app is not allowed to query for scheme comgooglemaps-x-callback吗?是否需要权限来查询它?
编辑:
我已经在我的info.plist中添加了以下项目,但仍然存在相同的问题。
<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
    <string>comgooglemaps-x-callback</string>
</array>

你在 plist 中添加了 LSApplicationQueriesSchemes 吗? - johny kumar
请在plist文件中添加以下内容:<key>LSApplicationQueriesSchemes</key> <array><string>comgooglemaps</string></array> - johny kumar
这是一个问题,请阅读此讨论:https://github.com/googlemaps/OpenInGoogleMaps-iOS/issues/3 - johny kumar
是的,我检查过了,但不知道为什么它仍然无法工作。 - Mehul Thakkar
1
尝试使用此链接 https://github.com/googlemaps/OpenInGoogleMaps-iOS。 - johny kumar
显示剩余2条评论
1个回答

7

您需要在Info.plist中添加一个LSApplicationQueriesSchemes条目,并列出您希望您的应用程序查询的方案。

<key>LSApplicationQueriesSchemes</key>
<array>
     <string>urlscheme</string>
     <string>urlscheme2</string>
     <string>urlscheme3</string>
     <string>urlscheme4</string>
</array>

请查看http://useyourloaf.com/blog/querying-url-schemes-with-canopenurl.html以获取相关信息(其中还包含与WWDC15会议对应的视频链接)。

添加了这个之后,仍然出现相同的错误。 - Mehul Thakkar
1
请检查修改后的问题,它仍然给我同样的问题。 - Mehul Thakkar

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接