UIActivityViewController not showing "Open in iBooks" option
Asked Answered
K

1

6

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.

Kablesh answered 22/4, 2013 at 18:42 Comment(3)
Did you try presentOptionsMenuFromBarButtonItem of UIDocumentInteractionController? - And I think that the initWithActivityItems argument of UIActivityViewController also accepts NSURL items in the array, that might help.Sena
Thanks for responding, but if you put an url in the array, it only shows the send by mail and publish on twitter options, and if you tap on send by mail, it opens the mail composer with a text containing the url, but without attaching the file..Kablesh
OK, it was just an idea! What about presentOptionsMenuFromBarButtonItem?Sena
T
10

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.

Tryparsamide answered 22/4, 2013 at 18:57 Comment(10)
Thank you very much, but if you open an attached PDF in a mail, you preview it and tap the button share, a popover is displayed and it has the options Open in iBooks and send by mail, how is it possible?Kablesh
Instead of using the presentOpenInMenuFromRect: method, use the presentOpenInMenuFromRect:` method of UIDocumentInteractionController.Tryparsamide
Sorry, but you've said the same thing...? about what method are you talking about for replacing the presentOpenInMenuFromRect: ?Kablesh
Sorry about that (copy/paste error). Replace your call to presentOpenInMenuFromRect:inView:animated: with presentOptionsMenuFromRect:inView:animated:.Tryparsamide
Yeah!!! that works like a charm! thank you very much! you're my hero! haha, how can I vote your last comment as the correct answer?Kablesh
I can't vote up because I have not enough reputation yet, but I marked as the correct answer, thank you very much again!Kablesh
@diegomen: Isn't that what I suggested in my first comment to your question ?Sena
@MartinR Nope, you suggested presentOptionsMenuFromBarButtonItem but the one I had to use is presentOptionsMenuFromRect:inView:animated.Kablesh
@Kablesh so you actually didn't use UIActivityViewController?Dominion
@JiFang UIActivityViewController only shows Activities but not "Open in..." options, even if there is only one activityItem. If your app allows multiple selection then it is a good idea to use the UIDocumentInteractionController for a single item, and UIActivityViewController for multiple itemsCompliant

© 2022 - 2024 — McMap. All rights reserved.