How to implement ‘Always Keep on This Device’ on macOS in File Provider?

345 views Asked by At

I am implementing a File Provider on macOS. I see that OneDrive has an offline mode with ‘Always Keep on This Device’ and ‘Free up Space’ menus:

enter image description here

On Windows, this functionality is provided by Pinned and Unpinned file attributes as well as CfHydratePlaceholder() and CfDehydratePlaceholder() Windows API. How do I implement this functionality on macOS? Are there any specific attributes or File Provider API to support it?

1

There are 1 answers

0
wangfu91 On

On macOS 13, there is a new API: NSFileProviderContentPolicy.

Set the NSFileProviderItem.contentPolicy to downloadEagerlyAndKeepDownloaded will achieve the same effect as Always Keep on This Device on Windows.

    /**
         Download this item eagerly (i.e before it is read.)
         Keep downloading remote updates eagerly.
         Prevent eviction on low disk pressure and other triggers.
    
         When an item with the inherited policy is moved into a folder with
         this policy, the system will automatically schedule a download.
         */
    @available(macOS 13.0, *)
    case downloadEagerlyAndKeepDownloaded = 3