Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS open app when file is tapped in `Files` app

Some iOS apps with custom file types get launched automatically when a file of that type is tapped (for example, Pages gets launched if a pages file is tapped in the Files app). How can an iOS app which is the owner of a UTI get the same behavior? (The UTI in particular conforms to com.apple.package)

I'm using the sample BeerTracking app from https://www.raywenderlich.com/133825/uiactivityviewcontroller-tutorial . When a file exported from the app is tapped in the Files app / Mail / Notes, an empty quicklook preview UI appears and only then is the user able to open the file in app by tapping share.

like image 291
Hristo Avatar asked Jun 10 '18 10:06

Hristo


People also ask

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

Open a file once with a specific app Select 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.

How do I choose which app opens a file on iPad?

On the latest version of stock Android, you need to open up the Settings app, then choose Apps & notifications, then Advanced, then Default apps. All the available categories, like browser and SMS, are listed. To change a default, just tap on the category, and make a new choice.


2 Answers

In the info.plist add the key "Supports opening documents in place" of type BOOLEAN and set it to TRUE.

You can than check with

BOOL openInPlace = [options[UIApplicationOpenURLOptionsOpenInPlaceKey] boolValue];

in

- (BOOL)application:(UIApplication *)app openURL:(NSURL *)url options:(NSDictionary<NSString *,id> *)options

if the provided url is a file that should be opened in place (most likely from the files app).

like image 126
D. Mika Avatar answered Nov 30 '22 05:11

D. Mika


At first you need to enable File Sharing. By add this 2 keys value YES in your Info.plist file

    1. UIFileSharingEnabled
    2. LSSupportsOpeningDocumentsInPlace

** You can do more stuff by using UIDocumentInteractionController link - https://developer.apple.com/documentation/uikit/uidocumentinteractioncontroller

  • To open a file type from iOS files app to your app, you need to have the cloud share functionality in your app so your app can share files into iCloud in a folder named by you app.

  • Then you can share any files to iCloud drive and they will show up in the iOS default files app.

  • When you tap any files from there (example - image, pdf, video) they will open in your app.

    UIFileSharingEnabled will do the work from you.

like image 23
Rahul Singha Roy Avatar answered Nov 30 '22 06:11

Rahul Singha Roy