我不知道如何检查手机上是否安装了应用程序!或者在安装App时,打开应用程序,否则打开Appstore链接以下载应用程序.我正在使用swift 3.我想用app name或bundle identifier来做.谢谢!
tor*_*ers 13
func openApp(appName:String) {
let appName = "instagram"
let appScheme = "/(appName)://app"
let appUrl = URL(string: appScheme)
if UIApplication.shared.canOpenURL(appUrl! as URL)
{
UIApplication.shared.open(appUrl!)
} else {
print("App not installed")
}
}
Run Code Online (Sandbox Code Playgroud)
Jon*_*ton 11
在其他答案和他们的评论之间,我的印象是提问者希望能够查看是否安装了任何给定的应用程序。
从 iOS 9.0 开始,这是不可能的。
iOS 9 及更高版本的应用程序在被允许使用canOpenURL:. 这是为了保护用户隐私,因为广告商正在以一种可以说是侵入性的方式滥用此功能。(有关这些更改的更多详细信息,请参阅这篇出色的帖子。)
当然,该列表是静态的,在构建时间或提交到 App Store 后无法更改。如果 Apple 不喜欢你选择的那些,他们完全有权拒绝它。
恐怕您要问的在 iOS 9.0 及更高版本的合理范围内是不可能的。
编辑:我还想说明一个应用程序的 URL 方案可能不一定与其名称很好地匹配。(这与其说是功能问题,不如说是一个命名不当的常量问题。)曾经有一个庞大的已知 URI 方案列表以及每个方案的文档,但令人痛心且恰如其分的是,托管它的 wiki 似乎已经关闭.
Ars*_*aik 10
After looking into so many answers, i am writing a common code which will help for new users. If you have two mobile apps as App1 and App2, if you want to check in App2 that App1 is already installed in his device or not, here is code below.
In App1 add this property in info.plist file
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.companyName.App1</string>
<key>CFBundleURLSchemes</key>
<array>
<string>App1</string>
</array>
</dict>
</array>
In App2 add this property in info.plist file
<key>LSApplicationQueriesSchemes</key>
<array>
<string>App1</string>
</array>
In App2 write the method to check if app is installed or not on phone! Or when App is installed, open the app, otherwise open the Appstore link to download the app as below.
func checkAndOpenApp(){
let app = UIApplication.shared
let appScheme = "App1://app"
if app.canOpenURL(URL(string: appScheme)!) {
print("App is install and can be opened")
let url = URL(string:appScheme)!
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
} else {
print("App in not installed. Go to AppStore")
if let url = URL(string: "https://apps.apple.com/us/app/App1/id1445847940?ls=1"),
UIApplication.shared.canOpenURL(url)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
I hope it will help some one.
斯威夫特 4.1。一名开发者可以在 AppStore 上拥有多个应用程序。因此,我需要检查用户是否安装了同一开发人员的其他应用程序。我有其他应用程序的捆绑包 ID。尽管您可以使用Appname而不是Bundle Id。所以我按照以下步骤操作。
在当前应用程序中,在 info.plist 文件中添加 Array 类型的 LSApplicationQueriesSchemes 键。输入您要从应用程序打开的应用程序的捆绑 ID 或应用程序名称。
其他应用程序应在该应用程序 URL 方案中具有其捆绑 ID 或应用程序名称条目。
Run Code Online (Sandbox Code Playgroud)let app = UIApplication.shared let bundleID = "some.Bundle.Id://" if app.canOpenURL(URL(string: bundleID)!) { print("App is install and can be opened") let url = URL(string:bundleID)! if #available(iOS 10.0, *) { UIApplication.shared.open(url, options: [:], completionHandler: nil) } else { UIApplication.shared.openURL(url) } } else { print("App in not installed. Go to AppStore") }
Run Code Online (Sandbox Code Playgroud)URL_scheme:// or Bundle_Id://
如果安装了应用程序,它将显示带有应用程序名称的警报,以在应用程序中打开它。
| 归档时间: |
|
| 查看次数: |
20743 次 |
| 最近记录: |