Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Airdrop error message: "cannot receive all of these items at the same time"

I use the following code to share an image, some text, and a url using UIActivityViewController. Everything works fine except that when the use selects AirDrop, it gets a "cannot receive all of these items at the same time". If I only share the image, then AirDrop works. I need the text and the url for email, Facebook, twitter sharing methods.

Is there a way to keep the text and the URL and make AirDrop only share the image while Facebook, email, twitter methods of sharing continue to use the text and url together with the image that I'm trying to share?

NSString *text = [NSString stringWithFormat:@"I made this image using %@ iOS app. Here is the link to download it:", [CloudHelper appName]];
NSURL *url = [NSURL URLWithString:APP_URL];    

UIActivityViewController *activityController =
[[UIActivityViewController alloc]
 initWithActivityItems:@[text, url, myImage]
 applicationActivities:nil];

[self presentViewController:activityController animated:YES completion:nil];
like image 217
RawMean Avatar asked Jun 25 '14 01:06

RawMean


1 Answers

You'd want to create and share three objects that conform to the UIActivityItemSource, where one returns a string, one an image and one a URL. Then when the delegate callback requesting the item is called you check which activity type was selected (Facebook, Twitter, airdrop, etc) and have some return nil if that item doesn't apply.

So in the case of airdrop, only the item source for the image will return a non-nil value. You can take a look at the airdrop sample code to get some examples of how to implement UIActivityItemSource

like image 87
ccjensen Avatar answered Sep 22 '22 02:09

ccjensen