Swift: How to open a new app when UIButton is tapped

后端 未结 5 559
一生所求
一生所求 2020-11-29 10:18

I have an app and when a uibutton is clicked, I want to open another app that is already installed (i.e. Waze). How can I do such? Big thanks.

5条回答
  •  时光说笑
    2020-11-29 10:51

    Try this. For example you want to open an Instagram app:

        var instagramHooks = "instagram://user?username=johndoe"
        var instagramUrl = NSURL(string: instagramHooks)
        if UIApplication.sharedApplication().canOpenURL(instagramUrl!)
        {  
            UIApplication.sharedApplication().openURL(instagramUrl!)
    
         } else {
            //redirect to safari because the user doesn't have Instagram
            UIApplication.sharedApplication().openURL(NSURL(string: "http://instagram.com/")!)
        }
    

提交回复
热议问题