How to open twitter page in twitter app from my iphone app?

后端 未结 5 1793
一向
一向 2021-02-04 01:44

The page I want to open using twitter app:

https://twitter.com/#!/PAGE

To open twitter app I use the following code:



        
5条回答
  •  悲&欢浪女
    2021-02-04 02:25

    This is the full code required in Swift. I am using Swift 4 but i believe it is the same for Swift 3.

    let Username =  "YOUR_USERNAME_HERE" 
    let appURL = NSURL(string: "twitter:///user?screen_name=\(Username)")!
    let webURL = NSURL(string: "https://twitter.com/\(Username)")!
    let application = UIApplication.shared
    if application.canOpenURL(appURL as URL) {
          application.open(appURL as URL)
        } else {
            // if Twitter app is not installed, open URL inside Safari
            application.open(webURL as URL)
        }
    

    Don't forget to add the Info keys needed to use canOpenURL:

提交回复
热议问题