15

I am using UIActivityViewController in that i added facebook, twitter and mail. After i complete share activity using any one of these feature how can i get the success callback.

Any ideas are appreciated,enter image description here

Maniganda saravanan
  • 2,188
  • 1
  • 19
  • 35

3 Answers3

21

Swift syntax:

let avc = UIActivityViewController(activityItems: [image], applicationActivities: nil)
avc.completionWithItemsHandler = { (activity, success, items, error) in
     print(success ? "SUCCESS!" : "FAILURE")
}

self.presentViewController(avc, animated: true, completion: nil)
Joel Teply
  • 3,260
  • 1
  • 31
  • 21
8

Set completion handler like this

[controller setCompletionHandler:^(NSString *act, BOOL success)
     {

         NSLog(@"act type %@",act);
         NSString *result = nil;

         if ( [act isEqualToString:UIActivityTypePostToTwitter] )  result = @"POST-SHARED-SUCCESSFULLY";
         if ( [act isEqualToString:UIActivityTypePostToFacebook] ) result = @"POST-SHARED-SUCCESSFULLY";

         if (success)
         {
             UIAlertView *av = [[UIAlertView alloc] initWithTitle:result message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil];
             [av show];
         }
         else
         {
             UIAlertView *av = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"ERROR", nil) message:nil delegate:nil cancelButtonTitle:NSLocalizedString(@"OK", nil) otherButtonTitles:nil];
             [av show];
         }
     }];
Dharmbir Singh
  • 17,485
  • 5
  • 50
  • 66
1

setCompletionHandler is deprecated. So if you are using iOS 8.0+ the here is the solution.

activityViewController.completionWithItemsHandler = ^(NSString *activityType, BOOL completed, NSArray *returnedItems, NSError *activityError) {
    // When the completed flag is YES, the user performed a specific activity
};