canOpenURL not working in ios 10 [duplicate]

不问归期 提交于 2019-12-06 02:07:53

问题


The above code is always returning false

if {(UIApplication.shared.canOpenURL(URL(string:"comgooglemaps://")!))}

I guess this a problem found in iOS10. I am trying to open google maps app if there in one installed or try to open apple maps so wanted to use canOpenURL . are there any alternatives


回答1:


Add this to your Info.plist and then try calling canOpenURL.

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
</array>



回答2:


Edit:

The correct key to be used in the app's plist file is LSApplicationQueriesSchemes and not UIDefaultLaunchStoryboard as stated by Apple's documentation.

Original answer:

From Apple's documentation:

If your app is linked on or after iOS 9.0, you must declare the URL schemes you want to pass to this method. Do this by using the UIDefaultLaunchStoryboard array in your Xcode project’s Info.plist file. For each URL scheme you want your app to use with this method, add it as a string in this array.

If your (iOS 9.0 or later) app calls this method using a scheme you have not declared, the method returns false, whether or not an appropriate app for the scheme is installed on the device.

You can read more about it here.



来源:https://stackoverflow.com/questions/40119595/canopenurl-not-working-in-ios-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!