Handing Off a Document
The converse of the situation discussed in the previous section is this: your app has somehow acquired a document that it wants to hand off 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 = [dic presentOptionsMenuFromRect:[sender bounds] inView:sender animated:YES];
Figure 36-2. The document Options action sheet and Open In action sheet
There are actually two action sheets available. The first action sheet in Figure 36-2, the Options action sheet, is summoned by
presentOptionsMenu...; the second action sheet in Figure 36-2, the Open In action sheet, is summoned by
presentOpenInMenu..., but it can also be summoned by one of the buttons in the first action sheet. These methods are cleverly designed to work on both iPhone and iPad interfaces; on the iPad, the buttons appear in ...