[[Twitter sharedInstance] logInWithCompletion runs twice


#1

I am using a custom button to create a twitter login button in my app. the IBAction for that button is:

[[Twitter sharedInstance] logInWithCompletion:^(TWTRSession *session, NSError *error) {
            if (session) {
                NSLog(@"signed in as %@", [session userName]);
                NSLog(@"userID %@", session.userID);
                NSLog(@"userToken %@", session.authToken);
                NSLog(@"userSecret %@", session.authTokenSecret);
                
               //code 
            } else {
                NSLog(@"Error: %@", [error localizedDescription]);
            }
        }];

The issue I am facing is that TwitterKit makes all actions twice: If the user has multiple accounts saved in iOS, it shows the action sheet to select account twice (tapping cancel shows the second open action sheet). If the user has no accounts saved in iOS, it opens the UIWebView for log in also twice. Any suggestions?


#2

I replied via email, but if anyone else is running into this:

The button (TWTRLogInButton) will log in all on its own, so having an extra OnClick() action is redundant.

import UIKit
import TwitterKit

class ViewController: UIViewController {

    @IBOutlet weak var twitterButton: TWTRLogInButton!
    
    override func viewDidLoad() {
        super.viewDidLoad()

        twitterButton.logInCompletion = { (session, error) in
            println("foo")
        }
    }
}

V


#3

@val Thanks a lot. By just setting the completion handler of the TWTRLoginButton solves the issue.


#4