Reputation: 3
I'd like to trigger a specific action after a user tweets something through iOS6's built-in "tweet sheet"
I want to trigger a method after the user hits its "Send" button.
Alternatively, if I can receive some confirmation from the iOS that a tweet was successfully posted, I'd like to trigger the method then.
Are either of these options possible? Is there a different, preferred way to trigger an action after a user posts a tweet?
Upvotes: 0
Views: 256
Reputation: 1265
-(void)shareViewTwitter:(NSString*)str
{
TWTweetComposeViewController *twitter = [[TWTweetComposeViewController alloc] init];
// Optional: set an image, url and initial text
[twitter setInitialText:@"Some Text"];
// Show the controller
[self presentModalViewController:twitter animated:YES];
// Called when the tweet dialog has been closed (Here your Action will be triggered)
twitter.completionHandler = ^(TWTweetComposeViewControllerResult result)
{
NSString *title = @"Tweet Status";
NSString *msg;
if (result == TWTweetComposeViewControllerResultCancelled)
// Your Action
msg = @"Tweet compostion was canceled.";
else msg = @"Tweet composition completed."; // Your Action
// Show alert to see how things went...
UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:title message:msg delegate:self cancelButtonTitle:@"Okay" otherButtonTitles:nil];
[alertView show];
// Dismiss the controller
[self dismissModalViewControllerAnimated:YES];
};
}
Upvotes: 2
Reputation: 5361
Use the completion handler. See code example below.
SLComposeViewController *tweetSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeTwitter];
tweetSheet.completionHandler = ^(SLComposeViewControllerResult result) {
switch(result) {
// This means the user cancelled without sending the Tweet
case SLComposeViewControllerResultCancelled:
break;
// This means the user hit 'Send'
case SLComposeViewControllerResultDone:
break;
}
dispatch_async(dispatch_get_main_queue(), ^{
[self dismissViewControllerAnimated:NO completion:^{
NSLog(@"Tweet Sheet has been dismissed.");
}];
});
};
Upvotes: 1