Opening Files Whose Type is Unknown
2010-08-15 20:45 Tracy E 阅读(560) 评论(0) 编辑 收藏 举报Opening Files Whose Type is Unknown (UIDocumentInteractionController)
How to use a document interaction controller:
1.Create an instance of the UIDocumentInteractionController class for each file you want to manage.
2.Present the file in your application's user interface.(Typically, you would di this by displaying the name or icon somewhere in your application)
3.When the user interacts with the file, ask the document interaction controller to present ont of the following interface:
# A file preview view that displays the contents of the file.
# A menu containing options to preview the file, copy its contents, or open it using another application.
# A menu prompting the user to open it with another application.
Creating and configuring a document interaction controller:
- (UIDocumentInteractionController *)docControllerForFile:(NSURL *)fileURL
{
UIDocumentInteractionController* docController = [UIDocumentInteractionController interactionControllerWithURL:fileURL];
[docController setDelegate:self];
return docController;
}
Presenting a document interaction controller:
You have the choice of displaying a document preview or of prompting the user to choose an appropriate action for the file using one of the following methods:
# Use the presentOptionsMenuFromRect:inView:animated: or presentOptionsMenuFromBarButtonItem:animate:method: to present the user with a verity of options.
# Use the presentPreviewAnimated: method to display a document preview.
# Use the presentOptionsInMenuFromRect:inView:animated: or presentOptionsInMenuBarButtonItem:animated: method to present the user with a list of applications with which to open the file.
Use the dismissMenuAnimated: or dismissPreviewAnimated: methods to dismiss the view programmatically.