I am trying to share a text (or an URL) and an image with AirDrop and it seems it sends only the image. It works fine with other sharing activities (Facebook, Twitter, Mail, Message etc.). Is it possible to share two items with AirDrop? Here is how I use the UIActivityViewController:

 UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[self.activityItem, self.attachedImage] applicationActivities:nil];

self.attachedImage is an UIImage and self.activityItem is a subclass of UIActivityItemProvider which returns different text for different activity types in delegate method

- (id)activityViewController:(UIActivityViewController *)activityViewController itemForActivityType:(NSString *)activityType

Does anyone have an idea? Thanks!

EDIT:

I also tried without subclassing UIActivityItemProvider and passed directly some text. Didn't work.

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"some text", self.attachedImage] applicationActivities:nil];

As a note, it works if I want to share multiple texts OR multiple images (UIImage):

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[@"text 1", @"text 2"] applicationActivities:nil];

    UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[attachedImage1, attachedImage2] applicationActivities:nil];
有帮助吗?

解决方案 2

Posted the same question on Apple Dev Forums: https://devforums.apple.com/message/937697#937697

Got this answer:

Currently not possible. AirDrop only lets you send sets of single items. If you are trying to send it to an instance of your own app on the other side, you could instead create a fileformat (a bundle/package would probably be suitable here) and embed all the different types with the file. Then on the receiving side you can extract the different types out of the file.

其他提示

Try this code

NSString *text= @"text to share";
CustomActivityItemProvider *textToShare = [[CustomActivityItemProvider alloc]
                                           initWithStandardText:text];

NSArray *activityItems = @[textToShare,self.attachedImage];

Use activityItems array in activity view controller.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top