Want to perform some action only when the post is successful via UIActivityViewController in iPhone

ios, iphone, objective-c, uiactivityviewcontroller, xcode

Solution

    [activityController setCompletionHandler:^(NSString *act, BOOL done)
             {

                 NSLog(@"act type %@",act);
                 NSString *ServiceMsg = nil;
                 if ( [act isEqualToString:UIActivityTypeMail] )           ServiceMsg = @"Mail sent";
                 if ( [act isEqualToString:UIActivityTypePostToTwitter] )  ServiceMsg = @"Post on twitter, ok!";
                 if ( [act isEqualToString:UIActivityTypePostToFacebook] ) ServiceMsg = @"Post on facebook, ok!";

                 if ( done )
                 {
                     UIAlertView *Alert = [[UIAlertView alloc] initWithTitle:ServiceMsg message:@"" delegate:nil cancelButtonTitle:@"ok" otherButtonTitles:nil];
                     [Alert show];
                     [Alert release];
                 }
                 else
                 {
                      // didn't succeed. 
                 }
             }];

use the completion handler's "done" parameter to check if completed or not

Problem

I am having an app in which i am using `UIActivityViewController`. This is the code i am using. ``` NSString *postText = @"My Text"; NSArray *activityItems = @[postText]; UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; activityController.excludedActivityTypes = [NSArray arrayWithObjects:UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, nil]; [self presentViewController:activityController animated:YES completion:nil]; ``` This works fine. When i open Twitter or E-Mail from `UIActivityViewController`, It shows the text i want to share and that is fine. But ,Now i want to perform some action in my DB only when the post is successful or The E-mail is sent successfully. How can i do that?

Original source