UIActivityViewController setCompletionWithItemsHandler未调用whatsapp活动

时间:2016-08-25 06:55:06

标签: ios objective-c uiactivityviewcontroller

UIActivityViewController setCompletionWithItemsHandler未调用whatsapp活动。

有没有人遇到同样的问题?如果有的话,请分享解决方案。

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:^{}];

1 个答案:

答案 0 :(得分:2)

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:^{

}];