Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// ログインボタンを押した時のアクションは自分で設定する
@IBAction func twitterLoginButtonTapped(sender: AnyObject) {
MBProgressHUD.showHUDAddedTo(self.view, animated: true)
}
// Twitterログインボタン設定
func setupLoginWithTwitter() {
// Consumer Key, Consumer Secretの指定
NCMBTwitterUtils.initializeWithConsumerKey(kTwitterConsumerKey, consumerSecret: kTwitterConsumerSecret)
// Twitterログインボタン押下時の処理
self.twitterLoginButton.loginMethods = [.WebBased]
self.twitterLoginButton.logInCompletion = { session, error in
Promise<TWTRSession>(resolvers: { (fulfill, reject) in
guard let session = session else {
reject(error!)
return
}
fulfill(session)
}).then({ (session) -> Promise<User> in
// NCMBでログイン
return Users.sharedInstance().loginWithTwitter(session)
}).then({ (user) -> Void in
print(user)
self.showSuccessNotice("Twitterログインしました")
self.performSegueWithIdentifier("showMain", sender: self)
}).always({
MBProgressHUD.hideAllHUDsForView(self.view, animated: true)
}).error({ (error) in
self.showErrorNotice("エラー", message: "Twitterログインに失敗しました")
print(error)
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment