6
votes

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.

2
Tapping on any file from the Files/Mail seems to open a quicklook preview UI for me, Pages documents included. I'm using the iOS 12 Beta and I have Pages installed.WolfLink
@WolfLink on my iOS 11 Device it opens directly the Pages App. But another problem I see is: what app should open a specific document type if multiple apps can open that type?Jonathan K

2 Answers

2
votes

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).

1
votes

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.