Open a users twitter profile page from iOS app

前端 未结 2 1936
南笙
南笙 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:40

    OK, there are two easy steps to achieve this in Swift 4:

    First, you have to modify Info.plist to list instagram and facebook with LSApplicationQueriesSchemes. Simply open Info.plist as a Source Code, and paste this:

    LSApplicationQueriesSchemes
    
        twitter
    
    

    After that, you can open twitter apps. Here is a complete code for twitter you can link this code to any button you have as an Action:

    @IBAction func followOnTwitter(sender: AnyObject) {
       let screenName =  "AffordIt_App"
       let appURL = NSURL(string: "twitter://user?screen_name=\(screenName)")!
       let webURL = NSURL(string: "https://twitter.com/\(screenName)")!
    
       let application = UIApplication.shared
    
       if application.canOpenURL(appURL as URL) {
            application.open(appURL as URL)
       } else {
            application.open(webURL as URL)
       }
    }
    

提交回复
热议问题