6

I need your help with UIActivityViewController. I need to present activity controller for the file where, except for default actions, the user will be able to open the file in other apps. I know how to do this with UIDocumentController, which shows popover with all apps able to open the file. But how can I show all these apps in UIActivityViewController?

P.S. This behavior can be seen in Apple Mail app, for example.

Kanan Vora
  • 2,124
  • 1
  • 16
  • 26
Yevgeniy Leychenko
  • 1,287
  • 11
  • 25
  • You can't directly in UIActivityViewController. Instead, you'll need to show your own UIDocumentController as a custom UIActivityItem. – klcjr89 Mar 18 '14 at 15:56
  • Apple Mail app did it. So I assume it is possible, right? – Yevgeniy Leychenko Mar 19 '14 at 06:59
  • Hi bro, did you solve this? I need exactly the same functionality and it seems rather sane to have it all in one place - printing, sharing, mailing and open in... – Stas Aug 20 '14 at 14:27
  • Believe it or not, but you'd have to use your own custom built `UIActivityItem` for each and every app which may or may not present a `UIDocumentController`. Like with Instagram, for instance. And never look for stock apps to find proof of something being possible. Only look at 3rd party apps. – Sergey Grischyov Aug 20 '14 at 14:36
  • http://stackoverflow.com/a/20306652/1606125 this is where you will get the help for your question probably the answer. Have a good time buddy. – Pankaj Wadhwa Aug 22 '14 at 08:44

3 Answers3

6

Look at TTOpenInAppActivity for a way to combine both a UIActivityViewController (for normal sharing), and an 'Open in' button on that which brings up a UIDocumentInteractionController. Pre-iOS 8, that is the best way to manage this.

Rob Glassey
  • 2,237
  • 20
  • 21
  • And what is the best way for iOS 8? – Sergey Skoblikov Nov 10 '14 at 20:07
  • 1
    Still valid if you're sharing, but if you're wanting to open/save documents _within_ other apps containers you'll be wanting to use the new `UIDocumentPickerViewController` instead. Also, it might be more appropriate in some export type circumstances as well... Depends on what you need, more choices that's all, so what's 'best' for you may vary. – Rob Glassey Nov 10 '14 at 20:18
  • Does `UIDocumentPickerViewController` implement the default actions (print, copy etc)? It doesn't appear to be a good replacement from that perspective – 1800 INFORMATION Jun 04 '15 at 23:10
4

The function and behavior is different between UIActivityViewController and UIDocumentController.

UIActivityViewController
Presents activities that are pre-defined, you can pass an array to select which ones should be excluded among the default ones that are presented, if you want to add more activities you have to use custom activities, unfortunately these will appear bellow the rest of the activities and even more, the icon will always be gray, your app never loses control since you can use delegates and other stuff to know what is going on on those apps. (Unless you manually make an activity which opens another app)

UIDocumentController
This one asks the system for all the registered applications for a certain file extension, many apps have registered their exclusive extensions which makes it so that this app will be the only one displayed. If you pass an image, you will see all the apps that can handle this file. When using this one your app will lose control since the other app will be opened.

What is your final objective?, If you describe it with more detail we could offer you a better solution.

From what i understand, you should see yourself what type of file the user is trying to open, and then yourself open it with the most suitable one. Since you cant really emulate what apple is doing, you should handle this problem through your interface, offer the user to "share" or to "open with" for example.

Pochi
  • 13,391
  • 3
  • 64
  • 104
  • I need to present a popover with some default actions like - print, share, email (which is UIActivityViewController is suitable for) but I also need a functionality to open file in other app...It's just a common sense to have all these in one popover.. – Stas Aug 27 '14 at 16:14
1

The answer is very simple. There is no way to do it. You cannot add the apps except the defaults into the UIActivityViewControllers.

You are absolutley correct, you can acheive this through the UIDocumentInteractionController.

Shamsudheen TK
  • 30,739
  • 9
  • 69
  • 102