This bug is fixed by WhatsApp team on 23rd May, 2016 (build no. 2.16.4).
Unable to share NSString object using UIActivityViewControll
have faced same issue after updating whatsapp. Even you press "cancel" on whatsapp still completion block shows success. i have resolved it by using "WFActivitySpecificItemProvider" and "WFActivitySpecificItemProvider"when sharing on whatsapp then dissmiss activityViewController and share via ur. You can pull WFActivitySpecificItemProvider, activityViewController classes from https://github.com/wileywimberly/WFActivitySpecificItemProvider
here is my code
- (void)share{
NSString *defaultMessage = @"your message may contain url";
// Use a dictionary
WFActivitySpecificItemProvider *provider1 =
[[WFActivitySpecificItemProvider alloc]
initWithPlaceholderItem:@""
items:@{
WFActivitySpecificItemProviderTypeDefault : defaultMessage,
UIActivityTypePostToFacebook : defaultMessage,
UIActivityTypeMail : defaultMessage,
UIActivityTypeMessage : defaultMessage,
@"com.linkedin.LinkedIn.ShareExtension":defaultMessage,
UIActivityTypePostToTwitter : defaultMessage
}];
// Use a block
WFActivitySpecificItemProvider *provider2 =
[[WFActivitySpecificItemProvider alloc]
initWithPlaceholderItem:@""
block:^(NSString *activityType){
if ([activityType isEqualToString:@"net.whatsapp.WhatsApp.ShareExtension"]) {
[avc dismissViewControllerAnimated:NO completion:nil];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
NSString *string = [NSString stringWithFormat:@"whatsapp://send?text=%@",defaultMessage];
NSURL *url = [NSURL URLWithString:[string stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL: url];
});
}
return defaultMessage;
}];
avc = [[UIActivityViewController alloc]
initWithActivityItems:@[provider1, provider2]
applicationActivities:nil];
[avc dismissViewControllerAnimated:YES completion:nil];
[avc setValue:sharingHeader forKey:@"subject"];
[avc setCompletionHandler:^(NSString *activityType, BOOL completed) {
if (activityType) {
NSLog(@"activity: %@ completed: %@",activityType,completed ? @"YES" : @"NO");
} else {
NSLog(@"No activity was selected. (Cancel)");
}
}];
[self presentViewController:avc animated:YES completion:nil];
}