Bablu Joshi Bablu Joshi - 3 months ago 44
iOS Question

UIActivityViewController setCompletionWithItemsHandler not called for whatsapp activity

UIActivityViewController setCompletionWithItemsHandler not called for whatsapp activity.

Has anyone faced the same issue? Please share solution if any.

NSArray *applicationActivities = @[[[JBWhatsAppActivity alloc] init]];

UIActivityViewController* activityViewController = nil;
if(installed)
activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil];
else
activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:applicationActivities];

// Setting subject field while sharing app with email
[activityViewController setValue:@"Check out this Site !" forKey:@"subject"];

NSArray *excludedActivities = @[UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop
];
activityViewController.excludedActivityTypes = excludedActivities;



[activityViewController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError)
{

}
];


[self presentViewController:activityViewController animated:YES completion:^{}];

Answer
NSMutableArray *sharingItems = [NSMutableArray new];
if (text) {
    [sharingItems addObject:text]; // text to share
}
if (image) {
    [sharingItems addObject:image]; // UIImage to share
}
if (url) {
    [sharingItems addObject:url]; // url to share
}

UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems applicationActivities:nil];

if ( [activityController respondsToSelector:@selector(popoverPresentationController)] ) {
    // iOS8
    activityController.popoverPresentationController.sourceView =
    sourceView;
    activityController.popoverPresentationController.sourceRect = CGRectMake(CGRectGetMidX(self.view.bounds), CGRectGetMidY(self.view.bounds),0,0);
}

[activityController setCompletionWithItemsHandler:^(NSString * __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError)
{
     //Your Code goes here
}];

[self presentViewController:activityController animated:YES completion:^{

}];
Comments