Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController: How to get if the activity is completed or not

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

like image 379
Maniganda saravanan Avatar asked Jan 31 '14 13:01

Maniganda saravanan


3 Answers

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)
like image 68
Joel Teply Avatar answered Nov 14 '22 09:11

Joel Teply


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];
         }
     }];
like image 8
Dharmbir Singh Avatar answered Nov 14 '22 09:11

Dharmbir Singh


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
};
like image 1
Upendra Siripurapu Avatar answered Nov 14 '22 08:11

Upendra Siripurapu