canOpenURL not working in ios 10 [duplicate]

2019-04-09 08:07发布

This question already has an answer here:

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

2条回答
啃猪蹄的小仙女
2楼-- · 2019-04-09 08:54

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

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>comgooglemaps</string>
</array>
查看更多
Root(大扎)
3楼-- · 2019-04-09 09:00

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.

查看更多
登录 后发表回答