macOS FileProvider fetchContents does not work

I try the sample codes for MacOS File Provider from this link (https://github.com/peterthomashorn/macosfileproviderexample/tree/main), and I can see 'a file' document is displayed in Finder when browse 'SomeProduct - Some Domain' at Locations. I debug to see if 'fetchContents' method of FileProviderExtension works but it is not called when I double-click to open 'a file' document from Finder.

What should I do to make 'fetchContents' method work when implement a File Provider?

Thanks
For more information, according to Apple's documentation it says that "The system can also convert dataless copies to materialized copies, as needed. For example, if the user opens a dataless file, the system calls fetchContentsForItemWithIdentifier:version:request:completionHandler: and saves the file’s content. For a dataless folder, the system calls enumeratorForContainerItemIdentifier:request:error: to enumerate the folder’s content.", fetchContents should be called when I open the file but it seems not work.

Hi trungflm,

Xcode's File Provider Extension template is not enough for fetchContentsForItemWithIdentifier:version:request:completionHandler: to work as you have expected it too.

You will need to update the method to call the completionHandler with the NSURL to the file containing the file's data (downloaded by your extension to a temporary location) and a NSFileProviderItem instance that represents the file.

The template's default implementation of the NSFileProviderItem protocol also needs implementations for the following optional properties:

@property (nonatomic, readonly, copy, nullable) NSNumber *documentSize;
@property (nonatomic, readonly, copy, nullable) NSDate *creationDate;
@property (nonatomic, readonly, copy, nullable) NSDate *contentModificationDate;

Once I implemented those properties, I was able to download a file using my own File Provider implementation.

Omar

macOS FileProvider fetchContents does not work
 
 
Q