Skip to content

Instantly share code, notes, and snippets.

@JayachandraA
Created May 4, 2017 12:14
Show Gist options
  • Save JayachandraA/9516fe3dfe4a3de71d7870b2460a3717 to your computer and use it in GitHub Desktop.
Save JayachandraA/9516fe3dfe4a3de71d7870b2460a3717 to your computer and use it in GitHub Desktop.
//check twitter services/account availability
if SLComposeViewController.isAvailable(forServiceType: SLServiceTypeTwitter) {
let composer = SLComposeViewController(forServiceType: SLServiceTypeTwitter)
//set sharing text
composer?.setInitialText(message)
//add image you want to share
composer?.add(image)
//add url you want to share
composer?.add(URL(string: "http://www.jaychandra.in")!)
composer?.completionHandler = ({ (status:SLComposeViewControllerResult) in
switch status {
case .cancelled:
print("cancelled")
case .done:
print("sent'")
DispatchQueue.main.async {
self.showAlert(title: "Success", message: "Shared successfully")
}
}
})
present(composer!, animated: true, completion: nil)
}else{
//there is no twitter account linked to the settings
//show error message to link the twitter account
print("there is no twitter account linked to the settings")
self.showAlert(title: "Error", message: "There is no twitter account linked to the settings, please link your account to share.")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment