How to open fb and instagram app by tapping on button in Swift

前端 未结 8 2438
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-30 03:17

How can I open Facebook and Instagram app by tapping on a button in swift? Some apps redirect to the Facebook app and open a specific page. How can I do the sam

8条回答
  •  甜味超标
    2020-11-30 03:43

    Take a look at these links, it can help you:

    https://instagram.com/developer/mobile-sharing/iphone-hooks/

    http://wiki.akosma.com/IPhone_URL_Schemes

    Open a facebook link by native Facebook app on iOS

    Otherwise, there is a quick example with Instagram for opening a specific profile (nickname: johndoe) here:

    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/")!)
    }
    

提交回复
热议问题