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
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];
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With