Skip to content

Instantly share code, notes, and snippets.

@hiromi2424
Last active May 20, 2016 09:31
Show Gist options
  • Save hiromi2424/4f38e7978daaddf6b92ad88b8fafb3e0 to your computer and use it in GitHub Desktop.
Save hiromi2424/4f38e7978daaddf6b92ad88b8fafb3e0 to your computer and use it in GitHub Desktop.
// ログインボタンを押した時のアクションは自分で設定する
@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