Thanks @grimashka, I tried something similar and this code is working correctly for me. Perhaps this or something similar would help?
- (void)viewDidLoad {
[super viewDidLoad];
TWTRLogInButton *logInButton = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession *session, NSError *error) {
if (!error && session) {
NSString *message = [NSString stringWithFormat:@"@%@ logged in! (#%@)",
[session userName], [session userID]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logged in!"
message:message
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alert show];
}
else if (error) {
NSString *userID = [[[[Twitter sharedInstance] sessionStore] session] userID];
if(userID){
[[[Twitter sharedInstance] sessionStore] logOutUserID:userID];
}
}
else {
NSString *userID = [[[[Twitter sharedInstance] sessionStore] session] userID];
if(userID){
[[[Twitter sharedInstance] sessionStore] logOutUserID:userID];
}
}
}];
// TODO: Change where the log in button is positioned in your view
logInButton.center = self.view.center;
[self.view addSubview:logInButton];
}