Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController not showing "Open in iBooks" option

I have a problem in my app. After getting some statistics, I generate a PDF file, and I want to show an UIActivityViewController with the options "Open in iBooks" and "Send By Mail" mainly (others like "Open in Dropbox" would be great to).

Well the thing is that before trying to use UIActivityViewController, I was using UIDocumentInteractionController, with the following code:

self.docController = [UIDocumentInteractionController interactionControllerWithURL:url];
self.docController.delegate = self;
[_docController presentOpenInMenuFromRect:_openInIBooksButton.bounds inView:self.openInIBooksButton animated:YES];

Where url is a path like /Documents/../statistics.pdf. It worked, it showed a popover with the buttons open in iBooks and open in Dropbox, but not Send by Mail. Now I've changed it with the following code:

NSArray* itemsToShare = [NSArray arrayWithObjects:pdfData, nil];
UIActivityViewController *activityVC = [[UIActivityViewController alloc] initWithActivityItems:itemsToShare applicationActivities:nil];
activityVC.excludedActivityTypes = @[UIActivityTypeCopyToPasteboard]; //or whichever you don't need
[self presentViewController:activityVC animated:YES completion:nil];

Where pdfData is a NSData object. And it works too, but now it shows the option of sending it by email, but not the iBooks option. I'm going nuts because I don't find the reason of that behavior and I need the two options, iBooks and Mail.

I don't know if it has something to do with the fact that the UIDocumentInteractionController has a path which ends with .pdf and the UIActivityViewController only has a NSData object. But I can't find a solution for that.

Somebody has found that problem before?

Thank you very much.

like image 455
diegomen Avatar asked Apr 22 '13 18:04

diegomen


1 Answers

When you use presentOpenInMenuFromRect:inView:animated: you only get a list of apps that can work with the given file.

What you want to use is presentOptionsMenuFromRect:inView:animated: which gives you the options that you are looking for.

like image 157
rmaddy Avatar answered Sep 20 '22 21:09

rmaddy