[iOS]TWTRLogInButton was created with no completionBlock set

ios
login

#1

Hello guys,

I have very strange problem. The completionBlock on TWTRLogInButton does not work. Here is my code:

AppDelegate.m

[TwitterKit startWithConsumerKey:@"**********" consumerSecret:@"*****************"];
[Fabric with:@[Twitter]];

MyViewController.m
In my viewDidLoad method:

 self.btnLoginTwitter = [TWTRLogInButton buttonWithLogInCompletion:^(TWTRSession* session, NSError* error) {
    if (session) {
        NSLog(@"signed in as %@", [session userName]);
    } else {
        NSLog(@"error: %@", [error localizedDescription]);
    }
}];

And I get this error:

TWTRLogInButton was created with no completionBlock set

What do I need to do to?

Thank you


#2

My guess is that you created a button in IB, an outlet in your header, and set an override on the class to TWTRLogInButton. If that is the case, there is a method called setLogInCompletion that you can use to set the completion block after instantiation (your property is being instantiated for you when IB sets up the view controller).

In short, you will end up with something like:

[self.btnLoginTwitter setLogInCompletion:^(TWTRSession *session, NSError *error) {
        // play with Twitter session
        if(error != nil) {
            //error state

        } else {
        }
    }];

Hope this helps.

Edit: words


#3

Thank you very much. It is exactly the same.


#4