ios – UIActivityViewController setCompletionWithItemsHandler未调用whatsapp活动

前端之家收集整理的这篇文章主要介绍了ios – UIActivityViewController setCompletionWithItemsHandler未调用whatsapp活动前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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:^{}];

解决方法

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

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

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

}];
原文链接:/iOS/334422.html

猜你在找的iOS相关文章