Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Open file in another app

Tags:

ios

iphone

ipad

My app needs to open some file types in other apps, like dropbox app does, it could list the installed apps which could open specific types of file.

How can get the app list?

like image 747
Dongsheng Cai Avatar asked Aug 23 '11 06:08

Dongsheng Cai


People also ask

How do I open a file with a different program on Android?

To change default apps in Android, go to Settings > Apps > Default apps and pick which category you want to set a default app for. Then select the app you want to use for this category.

How do I open a file with a specific app IOS?

Open a file once with a specific appSelect the file in the Finder, choose File > Open With, then choose an app. Control-click the file, choose Open With, then choose an app. Open the app, then choose File > Open.


3 Answers

You'll want to use UIDocumentInteractionController. See also the Document Interaction Programming Guide.

like image 113
jtbandes Avatar answered Sep 19 '22 16:09

jtbandes


You can use QLPreviewController from the official docs.

like image 24
illuminatus Avatar answered Sep 21 '22 16:09

illuminatus


Expanding on jtbandes's answer, here's the code that worked for me:

NSURL *url = [NSURL fileURLWithPath:filePath];
UIDocumentInteractionController *popup = [UIDocumentInteractionController interactionControllerWithURL:url];
[popup setDelegate:self];
[popup presentPreviewAnimated:YES];

And don't forget to include this in your H file:

@interface MyViewController : UIViewController <UIDocumentInteractionControllerDelegate>

Also worth noting: this will open a new fullscreen view that has a Document Viewer, as well as the Share button that offers all the various apps that can open this file. If you're just looking for the Share popup, equivalent to the UIActivityViewController, this will do it, but with some extra functionality you may not want.

like image 27
Nerrolken Avatar answered Sep 19 '22 16:09

Nerrolken