in iOS swift I have 1000 URL of different apps with bundle Id, I I want to open app if exist in my device, how can I open? I can't get URL scheme if all apps, is there any other apps? Thanks.
CodePudding user response:
Use below function.
func openApp(appId : String) {
if let url = URL(string: "itms-apps://itunes.apple.com/app/\(appId)"),
UIApplication.shared.canOpenURL(url)
{
if #available(iOS 10.0, *) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
UIApplication.shared.openURL(url)
}
}
}
Usage
openApp(appId: "id284882215")
This will open facebook app else take to app store.
CodePudding user response:
we can use like this. For example you want to open an Instagram application
let instagram = "instagram://user?username=johndoe"
let instagramUrl = URL(string: instagram)!
if UIApplication.shared.canOpenURL(instagramUrl)
{
UIApplication.shared.open(instagramUrl)
} else {
UIApplication.shared.open(URL(string: "http://instagram.com/")!)
}