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,
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)
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];
}
}];
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
};
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