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

前端 未结 8 2422
佛祖请我去吃肉
佛祖请我去吃肉 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 04:02

    Based on accepted answer here is the way to do this more elegantly with Swift 4

    UIApplication.tryURL([
            "instagram://user?username=johndoe", // App
            "https://www.instagram.com/johndoe/" // Website if app fails
            ])
    

    And truly remember to add the scheme to allow the app to open. However even if you forget that instagram will open in Safari.

    The tryUrl is an extension similar to presented here: https://stackoverflow.com/a/29376811/704803

提交回复
热议问题