SpencerZ SpencerZ - 17 days ago 12
iOS Question

UIActivityViewController share apps list empty

I want to share images to wechat by UIActivityViewController, my code is below

UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"已为您复制消息内容,请在分享内容框中粘贴!" preferredStyle:UIAlertControllerStyleAlert];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"知道了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
UIActivityViewController *activityViewController =[[UIActivityViewController alloc] initWithActivityItems:array applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToFacebook,UIActivityTypeAirDrop];
[self presentViewController:activityViewController animated:TRUE completion:nil];
}];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:nil];


but the share pop menu get empty

enter image description here

where is wrong?

Any help will be appreciated! Thanks

EDIT:
I found my array is empty, because I add a wrong image into that array, image url is wrong. So my share pop menu is empty. Now, it solved! Thank u guys!

Answer

I think is occurs due to empty array so you need to pass filled array to ActivityController .

 NSArray * array = @[[NSString stringWithFormat:@"pass your data"], [NSURL URLWithString:@"http://www.google.com"]];// this occur due to this
UIActivityViewController *activityViewController =[[UIActivityViewController alloc] initWithActivityItems:array  applicationActivities:nil];
activityViewController.excludedActivityTypes = @[UIActivityTypePostToFacebook,UIActivityTypeAirDrop];
[self presentViewController:activityViewController animated:TRUE completion:nil];