简体   繁体   English

OpenUrl无法在iOS10上运行

[英]OpenUrl not working on iOS10

My app uses openURL to open Google Maps app. 我的应用使用openURL打开Goog​​le地图应用。 It works on iOS 9 but not on iOS 10. 它适用于iOS 9,但不适用于iOS 10。

I understand that this method was deprecated on iOS 10, and there's a new one with more parameters. 我知道这个方法在iOS 10上已被弃用,并且有一个新的参数更多。 However, I saw everywhere that it should still work, and changing to the new method will only prevent a warning in the xCode. 但是,我在任何地方都看到它仍然可以工作,并且更改为新方法只会阻止xCode中的警告。 I also want to still support iOS 9 and lower. 我还想支持iOS 9及更低版本。

Any help? 有帮助吗?

Thanks. 谢谢。

Add LSApplicationQueriesSchemes key in info.plist file. info.plist文件中添加LSApplicationQueriesSchemes键。

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

Use this.... 用这个....

Objective c 目标c

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"comgooglemaps://maps.google.com/maps"] options:@{} completionHandler:nil];

Swift 4 斯威夫特4

 guard let url = URL(string: "comgooglemaps://maps.google.com/maps") else {
      return //be safe
 }

if #available(iOS 10.0, *) {
    UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
   UIApplication.shared.openURL(url)
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM