UIActivityViewController vs UIDocumentInteractionController in ios
Asked Answered
T

2

13

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.

Triplicity answered 20/1, 2014 at 12:54 Comment(1)
Socking!! till now I am not able to get answer or no one even try to give answer!!!Triplicity
V
26

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 documentation:

A view controller that previews, opens, or prints files whose file format cannot be handled directly by your app.

...

Use this class to present an appropriate user interface for previewing, opening, copying, or printing a specified file. For example, an email program might use this class to allow the user to preview attachments and open them in other apps.

After presenting its user interface, a document interaction controller handles all interactions needed to support file preview and menu display. You can also use the delegate to participate in 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.

UIActivityViewController documentation:

A view controller that you use to offer standard services from your app.

...

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.

Virgil answered 20/1, 2014 at 13:57 Comment(2)
I actually have googled quite a bit and didn't see many comparisons of these two. Your answer was helpful.Runyon
One important difference: given the same source file, the share sheet from UIDocumentInteractionController includes Quick Look. The share sheet from UIActivityViewController does not.Epley
K
4

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

Knout answered 20/1, 2014 at 13:56 Comment(3)
Depends: If you have an image file then yes. If all you have is an instance of UIImage then it isn't a file.Knout
UIActivityViewController has no problem with sharing PDFs contained in an NSData object, by the way. The difference is really mostly data vs files.Retinitis
We can share files with the help of UIActivityViewController. @sangony's answer makes lot of senseRoyster

© 2022 - 2024 — McMap. All rights reserved.