Search code examples
iosiclouduidocumentuti

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.


Solution

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