iOS 5 Twitter Framework 是一种用于在 iOS 应用程序中集成 Twitter API 的框架。要使用该框架发送直接消息,请按照以下步骤操作:
TWTweetComposeViewController
类来创建 Twitter 消息。composeViewDidFinish
方法中,调用 sendDirectMessage
方法发送直接消息。示例代码:
class ViewController: UIViewController, TWTweetComposeViewControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
if let tweetComposeViewController = TWTweetComposeViewController(delegate: self, cancelButtonTitle: "Cancel", image: UIImage(named: "twitterIcon")) {
view.addSubview(tweetComposeViewController.view)
tweetComposeViewController.modalTransitionStyle = .coverVertical
tweetComposeViewController.modalPresentationStyle = .fullScreen
}
}
func tweetComposeViewControllerDidFinish(_ tweetComposeViewController: TWTweetComposeViewController) {
tweetComposeViewController.dismiss(animated: true, completion: nil)
}
func sendDirectMessage(sender: AnyObject, message: String) {
if let tweetVC = sender as? TWTweetComposeViewController {
tweetVC.sendTweet(message)
}
}
}
注意:在使用此代码之前,请确保您已经在项目中添加了 Twitter Framework。
领取专属 10元无门槛券
手把手带您无忧上云