【发布时间】:2018-01-15 11:39:49
【问题描述】:
我的设备中有父子应用程序。我需要检查并打开父应用程序。在我的应用程序委托中(当应用程序启动时),我正在检查应用程序是否已安装,然后打开父应用程序,否则转到应用程序商店。
我已尝试以下代码来检查您的设备中是否安装了应用程序。
我是按照给定的 URL 类型创建的 -
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>Parent</string>
</array>
<key>CFBundleURLName</key>
<string>parentAppBundleid</string>
</dict>
</array>
我在 didFinishLaunchingWithOptions 中编写了以下代码-
func openGoYoApp() {
let parentapp = "Parent://"
let parentAppUrl = URL(string: parentapp)
if UIApplication.shared.canOpenURL(parentAppUrl! as URL)
{
UIApplication.shared.open(parentAppUrl!)
}
else {
//redirect to safari because the user doesn't have Instagram
print("App not installed")
UIApplication.shared.open(URL(string: "ituneLink")!)
}
}
在给定的条件下,如果返回 true 并且 UIApplication.shared.open(parentAppUrl!) 被执行但它没有打开我的父应用程序。
【问题讨论】:
标签: ios swift url-scheme