I managed to make it work (iOS 11+):
First you need to have a working File Provider extension for your app. Which I had already.
Then added my extension's File Provider and File Provider Item classes to my main app.
The only thing that didn't work out of the extension was trying to access the File Provider's documentStorageURL
. I fixed this by implementing a getter inside my custom class:
- (NSURL *)documentStorageURL
{
return NSFileProviderManager.defaultManager.documentStorageURL;
}
Then I could initialize it and use it from my main app:
// I created a singleton for my custom FileProvider class
NSURL* url = [FileProvider.sharedFileProvider URLForItemWithPersistentIdentifier:item.itemIdentifier];
// Calling providePlaceholderAtURL is key
[FileProvider.sharedFileProvider providePlaceholderAtURL:url completionHandler:^(NSError * _Nullable error)
{
if (error)
{
// ...
}
// This will download the requested file from my server
[FileProvider.sharedFileProvider startProvidingItemAtURL:url completionHandler:^(NSError * _Nullable error)
{
[APP_DELEGATE hideHUD];
if (error)
{
// ...
}
// Now I can use the url to start a UIDocumentInteractionController
UIDocumentInteractionController * controller = [UIDocumentInteractionController interactionControllerWithURL:url];
// Call presentOpenInMenuFromRect ...
}];
}];
This makes Word (and other Office and apps) display "Open in Word" instead of "Copy to Word", allowing in-place editing directly from my app.
Using my extension's classes and calling providePlaceholderAtURL
(which creates hidden (.myfile.docx.icloud
files) magically makes Word believe that the file is coming from the Files app.