Post

Replies

Boosts

Views

Activity

FileProvider: Photo / Thumbnail Download Implementation
Hello everyone, I am trying to implement the FileProvider API on macOS Big Sur for synching photos between my remote cloud storage and the local file system. In order to achieve this, I've implemented the fetchContents and fetchThumbnails calls in the FileProviderExtension.swift file that was generated by the extension template of Xcode (the latest 12.5 release of Xcode includes this). I have reached a state, where the download of thumbnails seems to work and I can also double-click the photo in Finder to display the full size picture. But still, there is stuff happening in FileProvider that I do not understand. Also, I am not sure, whether my implementation of these two methods is correct. Anyone that could give some details on how to do this properly? Let's quickly go into details for each method: fetchContents What We Do For the given itemIdentifier, fetch the file contents from remote cloud storage (via networking call) Pass the file URL and FileProviderItem back via completion handler (Error is nil in this case) In case of error, I would also call completion handler, but this time, I only set FileProviderItem and Error accordingly Questions I need to pass a FileProviderItem via completion handler. Where should I usually get this from? Atm, FileProviderItem objects are generated by myself during invocation of "enumerateItems" and I keep those objects for us in memory (e.g. to be returned in fetchContents completion handler). But this seems not to be the best way to do it. How is this supposed to work? I'm currently using URLSessionDownloadTask to download the file from remote storage. URLSessionDownloadTask will automatically store the file somewhere in the /var/folder/... directory structure (if not specified otherwise) with a file URL like file:///var/folders/8z/b57tvxbj7_x9ckvjq_fb9k680000gp/T/com.foo.GiraffeApp.GiraffeFileProvider/CFNetworkDownload_LFSN0y.tmp. I've observed that, if passing this file URL via the fetchContents completion handler, there are issues with the thumbnails (they are not properly displayed in Finder - they look broken). But if I copy that file over to the user's home directory somewhere and then pass that file URL via completion handler, thumbnail display in Finder works as expected (at least for me). I cannot explain this behaviour. On "fetchContents" documentation page - https://developer.apple.com/documentation/fileprovider/nsfileproviderreplicatedextension/3553303-fetchcontents there this a note that says: "The URL you pass to the completion handler must be on the same volume as the URL returned by the file provider manager’s temporaryDirectoryURL() method, so that the system can clone it to provide the content for the dataless item." How is this implemented in practice? Is that critical? What happens, if I do not follow this instruction (will FileProvider simply not work?). I am not checking this for now. fetchThumbnails What We Do For the given list of itemIdentifiers, fetch the thumbnail from remote cloud storage (via networking call). Download tasks are part of a dispatch group. As soon as all thumbnails in the list have finished downloading, the dispatch group's completion handler will be invoked. Thanks a lot for your help. And sorry for the messy code - my Swift skills are starting to evolve. André fetchContents - https://developer.apple.com/forums/content/attachment/c771bb24-1637-4709-b18b-4bfa2dad511a fetchThumbnails - https://developer.apple.com/forums/content/attachment/ccdd9649-ae40-4314-86cf-1e9a6f9896c6
0
0
810
May ’21