Open a users twitter profile page from iOS app

前端 未结 2 1935
南笙
南笙 2021-02-15 12:48

I am trying to deep link from my app to a user\'s twitter profile on the native twitter app. I have added schema rules for twitter and the following code:

    ap         


        
2条回答
  •  盖世英雄少女心
    2021-02-15 13:46

    Use this for twitter profile share, Swift 4:

        let screenName =  "NJMINISTRIESINC"
        let appURL = URL(string: "twitter://user?screen_name=\(screenName)")!
        let webURL = URL(string: "https://twitter.com/\(screenName)")!
    
        if UIApplication.shared.canOpenURL(appURL as URL) {
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(appURL)
            } else {
                UIApplication.shared.openURL(appURL)
            }
        } else {
            //redirect to safari because the user doesn't have Instagram
            if #available(iOS 10.0, *) {
                UIApplication.shared.open(webURL)
            } else {
                UIApplication.shared.openURL(webURL)
            }
        }
    

提交回复
热议问题