Using a URL to a document shared with you:
Once you have an NSURL:
[url startAccessingSecurityScopedResource];
// do the access. Examples: open, fread, NSFileManger move or copy.
[url stopAccessingSecurityScopedResource];
failure to access will leak kernel resources. UIDocument calls these for you.
NSURL's
- (NSData *)bookmarkDataWithOptions:(NSURLBookmarkCreationOptions)options
includingResourceValuesForKeys:(NSArray<NSURLResourceKey> *)keys
relativeToURL:(NSURL *)relativeURL
error:(NSError * _Nullable *)error;
creates bookmarks to save scoped access to use in other runs.
Getting the URL in the first place.
With Scenes:
func scene(_: UIScene, openURLContexts: Set<UIOpenURLContext>)
and
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions)
passes a connectionOptions.urlContexts (You have to handle them both)
where a UIOpenURLContext is a objc class with a url and an options , including options.openInPlace and options.eventAttribution, which seems to be concerned with advertisements.
Without Scenes:
func application(_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey : Any]) -> Bool
Other important classes
UIDocumentBrowserViewController - the root view controller of your app.
UIDocumentPickerViewController - choosing files, presented from one of your existing controllers.
UIDocumentInteractionController - an earlier way of sharing files out.
NSFileCoordinator - for reading and writing files, particularly those that may change in use due to sharing
NSFilePresenter - for displaying the content of an external document