Reputation: 6540
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.
Upvotes: 7
Views: 4880
Reputation: 636
At first you need to enable File Sharing. By add this 2 keys value YES in your Info.plist file
** 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.
Upvotes: 1
Reputation: 2808
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).
Upvotes: 6