Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Twitter completionHandler freezes app on success

Tags:

ios

twitter

ios5

After a completed tweet from TWTweetComposeViewController, my app locks up. Going out to the home screen and coming back seems to fix this, and the clock still ticks, but no touches register to any of my views/controls.

Thinking something weird must be happening in my app, I made a fresh utility-app-template project, linked it w/ Twitter.framework, and redefined the info UIButton's IBAction method to this:

- (IBAction)showInfo:(id)sender
{   
    TWTweetComposeViewController *twt = [[TWTweetComposeViewController alloc] init];
    [twt setInitialText:@"some garbage"];
    [twt addURL:[NSURL URLWithString:@"http://google.com"]];
    twt.completionHandler = ^(TWTweetComposeViewControllerResult r) { NSLog(@"it happened: %d",r); };
    [self presentViewController:twt animated:YES completion:NULL];
    [twt release];
}

After canceling (which takes 2 taps, interestingly), it can be brought back up by tapping the 'i', but after submitting, the 'i' is non-responsive until backgrounding the app.

Has anyone used this successfully? Or am I blatantly missing something?

like image 606
Ben Mosher Avatar asked Dec 02 '11 20:12

Ben Mosher


1 Answers

The problem here is that you are presenting a modal view controller (the twitter view controller is modal); however, your completion handler isn't dismissing the modal view controller when finished. This leaves the twitter controller to capture all the touches on the screen preventing your app from functioning properly.

You need to make sure you add [self dismissModalViewControllerAnimated:YES]; to your completion handler.

Something like this:

(IBAction)showInfo:(id)sender 
{   
    TWTweetComposeViewController *twt = [[TWTweetComposeViewController alloc] init];
    [twt setInitialText:@"some garbage"];
    [twt addURL:[NSURL URLWithString:@"http://google.com"]];
    twt.completionHandler = ^(TWTweetComposeViewControllerResult result) { 
      switch (result) {
        case TWTweetComposeViewControllerResultCancelled:                    
           break;

        case TWTweetComposeViewControllerResultDone:
           break;

        default:
           break;
      }
      [self dismissModalViewControllerAnimated:YES];
    };

    [self presentModalViewController:twt animated:YES];

};

like image 111
radesix Avatar answered Nov 15 '22 13:11

radesix