Swift 用于在我的 iPad 上打开下载的应用程序的程序
Swift program to open a downloaded app on my iPad
我现在正在开发一个应用程序,我正在尝试创建一个按钮来打开用户已下载的应用程序。由于之前的问题,我得到了一些工作代码 (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)
}
}
基本上,我有一个按钮,单击该按钮应该会打开我 iPad 上的 Microsoft Power BI 应用程序。不幸的是,我一直收到错误 "This app is not allowed to query for scheme mspbi? The URI I have is straight from Microsoft's website. Thoughts on how to open the app? It always skips the "if" 并直接转到 "else"
您必须将以下行添加到应用程序的 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>
您需要将 URL 方案添加到应用的 Info.plist
来自 Apple Developer Documentation for canOpenURL(_:)
:
Important
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 adding the
LSApplicationQueriesSchemes
key to your app's Info.plist
file. If you
call this method for a scheme not declared using that key, this method
always returns false, whether or not an appropriate app is installed.
To learn more about the key, see LSApplicationQueriesSchemes.
因此在 Info.plist
中使用键 LSApplicationQueriesSchemes
创建一个新的 Array
并添加一个值为 mspbi
.
的项目
我现在正在开发一个应用程序,我正在尝试创建一个按钮来打开用户已下载的应用程序。由于之前的问题,我得到了一些工作代码 (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)
}
}
基本上,我有一个按钮,单击该按钮应该会打开我 iPad 上的 Microsoft Power BI 应用程序。不幸的是,我一直收到错误 "This app is not allowed to query for scheme mspbi? The URI I have is straight from Microsoft's website. Thoughts on how to open the app? It always skips the "if" 并直接转到 "else"
您必须将以下行添加到应用程序的 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>
您需要将 URL 方案添加到应用的 Info.plist
来自 Apple Developer Documentation for canOpenURL(_:)
:
Important
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 adding the
LSApplicationQueriesSchemes
key to your app'sInfo.plist
file. If you call this method for a scheme not declared using that key, this method always returns false, whether or not an appropriate app is installed. To learn more about the key, see LSApplicationQueriesSchemes.
因此在 Info.plist
中使用键 LSApplicationQueriesSchemes
创建一个新的 Array
并添加一个值为 mspbi
.