繁体   English   中英

swift - 应用程序无法从另一个应用程序打开

[英]swift - App does not open from another app

我尝试从我的应用程序中打开优步应用程序。 它直接将我重定向到应用商店,而不是应用。 我希望它直接打开优步应用程序,而不是通过应用商店应用程序。 这是我的 function:

func callUrl(){
    if let url = NSURL(string: "Uber://"), UIApplication.shared.canOpenURL(url as URL) {
        UIApplication.shared.open(url as URL)
    } else if let itunesUrl = NSURL(string: "https://apps.apple.com/us/app/uber/id368677368"), UIApplication.shared.canOpenURL(itunesUrl as URL) {
        UIApplication.shared.open(itunesUrl as URL)
    }
}

我认为else语句被调用是因为"Uber://"可能是直接打开应用程序的无效键。

也许这对你有用

if let url = URL(string: "uber://"),
    UIApplication.shared.canOpenURL(url) {

    UIApplication.shared.open(url)
}
else {
    UIApplication.shared.open(URL(string: "https://apps.apple.com/us/app/uber/id368677368")!)
}

编辑

使用uber值将LSApplicationQueriesSchemes键添加到Info.plist

<key>LSApplicationQueriesSchemes</key>
<array>
    <string>uber</string>
</array>

优步文档

暂无
暂无

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

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