Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does the Twitter iOS API provide any way of determining if the tweet was successful?

Tags:

ios

twitter

ios5

I'm using the following snippet of code to make a tweet in my iOS 5 application :

- (IBAction)postToTwitterClicked:(id)sender 
{
    if ([TWTweetComposeViewController canSendTweet])
    {
        TWTweetComposeViewController *tweetSheet = [[TWTweetComposeViewController alloc]init];
        [tweetSheet setInitialText:@"Some sample message here"];
        [tweetSheet addURL:[NSURL URLWithString:@"http://myURL"]];

        [self presentModalViewController:tweetSheet animated:YES];
    }
    else 
    {
        UIAlertView *av = [[UIAlertView alloc] initWithTitle:@"Unable to tweet"
                                                     message:@"Please ensure that you have at least one twitter account setup and have internet connectivity. You can setup a twitter account in the iOS Settings > Twitter > login."
                                                    delegate:self 
                                           cancelButtonTitle:@"OK" 
                                           otherButtonTitles:nil];
        [av show]; 
    }
}

This works fine, but how do I know that the user did actually post a tweet, or if there was a problem?

Since this doesn't implement a delegate, there are no "onError" methods that I can override.

I want to know if the user did successfully post a tweet, so I can action some behaviour such as

  1. Disable a button so they can't do it again
  2. Notify them the post was successful and will show up in their feed shortly
like image 268
Jimmy Avatar asked Jan 25 '26 01:01

Jimmy


1 Answers

There is no way in the iOS Twitter API that you can see that a Tweet actually was posted on the server. But you can analyze the TWTweetComposeViewControllerResult to see if the tweet was finished composing successfully or if the tweet was cancelled.

twitter.completionHandler = ^(TWTweetComposeViewControllerResult res) {
    if (res == TWTweetComposeViewControllerResultDone) {
         // Composed
    } else if (res == TWTweetComposeViewControllerResultCancelled) {
        // Cancelled
    }
    [self dismissModalViewControllerAnimated:YES];
};
like image 111
Peter Warbo Avatar answered Jan 27 '26 15:01

Peter Warbo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!