UIActivityViewController vs UIDocumentInteractionC

2019-03-25 05:50发布

问题:

I just read some articles on UIActivityViewController and UIDocumentInteractionController in iOS, but I am very confused about how to use them because both seem the same.

So, when do I use UIActivityViewController or UIDocumentInteractionController?

Is there any difference for Open In... & use UIActivityViewController?

I am very confused about how to use them. Please clarify to me their specific use.

回答1:

In short, UIDocumentInteractionController deals with files while UIActivityViewController deals with various other services in your app. I'm not one to criticize much but you really should at least try to google and read at least the overview in the iOS Developer Docs.

UIDocumentInteractionController Overview:

A document interaction controller, along with a delegate object, provides in-app support for managing user interactions with files in the local system. For example, an email program might use this class to allow the user to preview attachments and open them in other apps. Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file.

After presenting its user interface, a document interaction controller handles all interactions needed to support file preview and menu display. In some cases the object employs a delegate to determine how to respond to specific commands. For example, to provide copying or printing, you must implement the documentInteractionController:canPerformAction: and documentInteractionController:performAction: delegate methods.

You can also use the delegate to participate with interactions occurring within the presented interface. For example, the delegate is notified when a file is about to be handed off to another application for opening. For a complete description of the methods you can implement in your delegate, see UIDocumentInteractionControllerDelegate Protocol Reference.

UIActivityViewController Overview:

The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

Your app is responsible for configuring, presenting, and dismissing this view controller. Configuration for the view controller involves specifying the data objects on which the view controller should act. (You can also specify the list of custom services your app supports.) When presenting the view controller, you must do so using the appropriate means for the current device. On iPad, you must present the view controller in a popover. On iPhone and iPod touch, you must present it modally.



回答2:

Basically UIActivityViewController shares Data Objects (like Strings or Images) where UIDocumentInteractionController shares whole Documents / Files f.e. a PDF.