代码之家  ›  专栏  ›  技术社区  ›  Davis

在我的iPad上打开下载应用程序的Swift程序[重复]

  •  1
  • Davis  · 技术社区  · 7 年前

    我现在正在开发一个应用程序,我正在尝试创建一个按钮来打开用户下载的应用程序。由于前面的问题,我得到了一些工作代码(Swift)。我有以下几点。

    @IBAction func Website(_ sender: Any) {
    
        let powerHooks = "mspbi://app/"
    
        let powerUrl = NSURL(string: powerHooks)
        if UIApplication.shared.canOpenURL(powerUrl! as URL)
        {
            UIApplication.shared.openURL(powerUrl! as URL)
    
        } else {
            //redirect to safari because the user doesn't have Power BI
            UIApplication.shared.openURL(NSURL(string: "http://powerbi.microsoft.com")! as URL)
        }
    }
    

    2 回复  |  直到 7 年前
        1
  •  2
  •   Dávid Pásztor    7 年前

    您必须在应用程序的 Info.plist 能够处理应用程序URL的文件:

    <key>LSApplicationQueriesSchemes</key>
    <array>
        <string>mspbi</string> //not sure if this is the correct entry, you will have to check for the specific app
        <string>uber</string>  //as an example, this is the working entry for opening the Uber app from your app
    </array>
    
        2
  •  0
  •   Paolo    7 年前

    你需要将URL方案添加到应用程序的 Info.plist

    Apple Developer Documentation canOpenURL(_:) :

    重要的

    要传递到此方法的URL方案。通过添加 LSApplicationQueriesSchemes 应用程序的 信息列表 为未使用该键声明的方案调用此方法,即此方法 无论是否安装了适当的应用程序,始终返回false。 LSApplicationQueriesSchemes .

    所以在 创建新的 Array LSApplicationQueriesSchemes 并添加一个有价值的项目 mspbi