我正在构建一个应用程序以将图片分享到Twitter。
我尝试使用社交网络进行操作,但是ios 11不再支持它。
@IBAction func ShareButtonTapped(_ sender: Any) {
TWTRTwitter.sharedInstance().start(withConsumerKey: "", consumerSecret: "")
if (TWTRTwitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
// App must have at least one logged-in user to compose a Tweet
guard let shareImg2 = UIImage.init(named: "twitter.png") else{
print("failed init share img")
return
}
//let shareImg = UIImage.init(named: "mountain")!
let composer = TWTRComposerViewController.init(initialText: "UK flag picture will be tweeted", image: shareImg2, videoURL: nil)
composer.delegate = self as? TWTRComposerViewControllerDelegate
present(composer, animated: true, completion: nil)
} else {
// Log in, and then check again
TWTRTwitter.sharedInstance().logIn { session, error in
if session != nil { // Log in succeeded
guard let shareImg2 = UIImage.init(named: "twitter.png") else{
print("failed init share img")
return
}
//let shareImg = UIImage.init(named: "mountain")!
let composer = TWTRComposerViewController.init(initialText: "USA flag picture will be tweeted", image: shareImg2, videoURL: nil)
composer.delegate = self as? TWTRComposerViewControllerDelegate
self.present(composer, animated: true, completion: nil)
} else {
let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
self.present(alert, animated: false, completion: nil)
}
}
}
因此,当我在应用程序中单击“共享”按钮时,它会打开Twitter,但不会将推文共享给Twitter,并在终端中发送一条消息
Could not load IOSurface for time string. Rendering locally
instead.