Handing Off a Document
The converse of the situation discussed in the previous section is this: your app has somehow acquired a document and wants to let the user hand off a copy of it to whatever app can deal with it. This is done through the UIDocumentInteractionController class. This class operates asynchronously, so retaining an instance of it is up to you; typically, you’ll store it in an instance variable with a retain setter policy.
For example, let’s say our app has a PDF sitting in its Documents directory. Assuming we have an NSURL pointing to this document, presenting the interface for handing the document off to some other application (Figure 36-2) could be as simple as this (sender
is a button that the user has just tapped):
self.dic = [UIDocumentInteractionController interactionControllerWithURL:url]; BOOL y = [self.dic presentOpenInMenuFromRect:[sender bounds] inView:sender animated:YES];
Starting in iOS 6, this interface is an activity view (Chapter 26); formerly, it was an action sheet. There are actually two activity views available:
-
presentOpenInMenuFromRect:inView:animated:
presentOpenInMenuFromBarButtonItem:animated:
- Presents an activity view listing apps in which the document can be opened.
-
presentOptionsMenuFromRect:inView:animated:
presentOptionsMenuFromBarButtonItem:animated:
- Presents an activity view listing ...
Get Programming iOS 6, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.