How to force macOS File Provider Extension to re-enumerate items

1.3k views Asked by At

Is there a way to force macOS File Provider Extension to re-enumerate items for given parent container?

I am aware that we can signalEnumerator(for: .workingSet) but that would just invoke the enumerateChanges callback in FileProviderEnumerator. What I'm looking for is something like: Internal structure changed so much, that it would be best to re-enumerate the content and rebuild the new model with it. And that should result in invoking the enumerateItems callback in the FileProviderEnumerator.

Are there any options to achieving just that?

2

There are 2 answers

1
mixtly87 On

Maybe deregistering and registering FileProvider domain could help.

To remove all domains and add domain again:

let identifier = NSFileProviderDomainIdentifier(rawValue: "Your-Domain-Identifier")
let domain = NSFileProviderDomain(identifier: identifier, displayName: "Your-Provider-Domain")

NSFileProviderManager.removeAllDomains { error in
    if error != nil {
        print("Error removing all domains: \(error)")
    } else {
        NSFileProviderManager.add(domain) { error in
            print("Error adding domain: \(error)")
        }
    }
}

This should result in re-fetching (enumerating) root container again and all its children as user browses content in Finder.

4
Stephane Klein On

I found a solution to this by calling the NSFileProviderManager reimportItems function:

manager.reimportItems(below: obj, completionHandler: {_ in })