Try this. For example you want to open an Instagram app:
let instagramHooks = "instagram://user?username=johndoe"
let instagramUrl = URL(string: instagramHooks)!
if UIApplication.shared.canOpenURL(instagramUrl)
{
UIApplication.shared.open(instagramUrl)
} else {
//redirect to safari because the user doesn't have Instagram
UIApplication.shared.open(URL(string: "http://instagram.com/")!)
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…