Last active
August 10, 2016 22:11
-
-
Save soggybag/c83ed5cc91702b5e4c9c to your computer and use it in GitHub Desktop.
Swift, post to FaceBook and Twitter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import Social | |
import MessageUI | |
class ViewController: UIViewController, MFMessageComposeViewControllerDelegate { | |
// MARK: Social | |
func postToFaceBook() { | |
let vc = SLComposeViewController(forServiceType: SLServiceTypeFacebook) | |
vc.setInitialText("Posting to FaceBook") | |
// vc.addImage(UIImage!) // Add an image | |
// vc.addURL(NSURL!) // Add a URL | |
presentViewController(vc, animated: true, completion: nil) | |
} | |
func postToTwitter() { | |
let vc = SLComposeViewController(forServiceType: SLServiceTypeTwitter) | |
vc.setInitialText("Posting to Twitter") | |
// vc.addImage(UIImage!) // Add an image | |
// vc.addURL(NSURL!) // Add a URL | |
presentViewController(vc, animated: true, completion: nil) | |
} | |
func sendMessage() { | |
let messageVC = MFMessageComposeViewController() | |
messageVC.body = "Your message string" | |
messageVC.recipients = [] | |
messageVC.messageComposeDelegate = self | |
presentViewController(messageVC, animated: true, completion: nil) | |
} | |
func messageComposeViewController(_ controller: MFMessageComposeViewController, | |
didFinishWithResult result: MessageComposeResult) { | |
// Do something after sending a message... | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment