我实现了 Twitter 分享按钮,但是没有像这张图片那样更改 Twitter 帐户的列。如果我从该帐户注销,我将无法授权(登录)另一个帐户。要授权的视图永远不会出现。
我的应用没有 2 列(“帐户”和“位置”)。所以除非我一开始授权,否则我不能更改帐户。我怎么解决这个问题?
(如果可能的话,最好在授权和推文一次后从所有帐户注销时能够授权帐户。但我不知道该怎么做......)
let shareImage = UIImage(named:"Twitter_shareImage")
let tweetDescription:String = "text"
TWTRTwitter.sharedInstance().sessionStore.saveSessionWithAuthToken(authToken, authTokenSecret: authTokenSecret, completion: { (session, error) -> Void in
if (TWTRTwitter.sharedInstance().sessionStore.hasLoggedInUsers()) {
if let session = TWTRTwitter.sharedInstance().sessionStore.session() {
let composer = TWTRComposer()
composer.setText("text")
composer.setImage(shareImage)
composer.show(from: self.parentViewController()!, completion: nil)
print(session.userID)
} else {
TWTRTwitter.sharedInstance().logIn {
(session, error) -> Void in
if (session != nil) {
// println("signed in as \(session.userName)");
} else {
// println("error: \(error.localizedDescription)");
}
}
print("no account")
}
} else {
// Log in, and then check again
TWTRTwitter.sharedInstance().logIn { session, error in
if session != nil { // Log in succeeded
let composer = TWTRComposer()
composer.setText("text")
composer.setImage(shareImage)
composer.show(from: self.parentViewController()!, completion: nil)
} else {
let alert = UIAlertController(title: "No Twitter Accounts Available", message: "You must log in before presenting a composer.", preferredStyle: .alert)
self.parentViewController()?.present(alert, animated: false, completion: nil)
}
}
}