iosswifttwittersocial-framework

How to add location to tweet in Swift?


I'm using the Social Framework to be able to share content from my app to Twitter. I'd like to be able to add a location to the tweet. Here's my code:

if SLComposeViewController.isAvailableForServiceType(SLServiceTypeTwitter) {
  let twitterComposeVC = SLComposeViewController(forServiceType: SLServiceTypeTwitter)   
  twitterComposeVC.setInitialText("I found a really nice spot. Check it out here")          
  self.presentViewController(twitterComposeVC, animated: true, completion: nil)
} else {
  self.showAlertMessage("Please make sure you're logged into Twitter in your device settings")
}

Solution

  • There is no option to add location to your Tweet using SLComposeViewController, a user has to set it explicitly. You will have to create a custom tweet sheet.

    There are libraries that do this (e.g. LGTweeter) but I haven't found any written in Swift (but you can use objective-c libraries in you Swift code).

    UPDATE:

    The LGTweeter has been removed from the GitHub, it can be found on the CocoaPods, but it seems that it'is no longer being developed.