【问题标题】:swift - App does not open from another appswift - 应用程序无法从另一个应用程序打开
【发布时间】:2020-04-07 07:31:53
【问题描述】:

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

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)
    }
}

【问题讨论】:

  • 您是否在 info.plist 中将 Uber 添加到您的 LSApplicationQueriesStrings 中?
  • 你确定需要添加它吗?

标签: ios swift xcode nsurlconnection func


【解决方案1】:

我认为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>

Uber Documentation

【讨论】:

  • 试过了,还是一样的问题
  • 这意味着 canOpenURL() 返回 false 并将您定向到应用商店,所以您能分享更多详细信息吗?比如打印UIApplication.shared.canOpenURL(url)false等的结果。
  • 这是日志:-canOpenURL: failed for URL: "uber://" - error: "This app is not allowed to query for scheme uber" 2020-04-07 16:07:14.632232+0200 Toasty Kiepscy[4558:1033901] Can't end BackgroundTask: no background task exists with identifier 1 (0x1), or it may have already been ended. Break in UIApplicationEndBackgroundTaskError() to debug.
  • @PawelZet 请检查我编辑的答案,我希望它会工作
  • 酷,现在可以使用了!谢谢 :) 我以后会知道的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2011-08-05
  • 2019-08-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多