Problem starting a macOS file provider extension

Hi,

I'm trying to get to the point when the code of my file provider extension gets executed.

As there is no Xcode template for macOS file provider extension target, I've created a FinderSync extension and updated its Info.plist NSExtension entry manually:
Code Block xml
<key>NSExtension</key>
<dict>
<key>NSExtensionFileProviderDocumentGroup</key>
<string>$(TeamIdentifierPrefix)group.xxxx.test-placeholders</string>
<key>NSExtensionFileProviderEnabledByDefault</key>
<true/>
<key>NSExtensionFileProviderSupportsEnumeration</key>
<true/>
<key>NSExtensionPointIdentifier</key>
<string>com.apple.fileprovider-nonui</string>
<key>NSExtensionPrincipalClass</key>
<string>FakeProvider</string>
</dict>

I use my main app to "bootstrap" the provider (i.e. to register a domain for file provider and trigger enumeration), i.e.:
Code Block swift
let domainID = NSFileProviderDomainIdentifier(rawValue: "blahblahblah")
let domain = NSFileProviderDomain(identifier: domainID, displayName: "My Secret Files")
NSFileProviderManager.add(domain) { (err) in
if let err = err {
/* handle error */
} else {
let mgr = NSFileProviderManager(for: domain)
mgr?.signalEnumerator(for: .rootContainer) {
err in
/* handle error if any */
}
}
}



I have limited success with this approach. My extension is visible in macOS Preferences -> Extensions. Finder shows newly registered domain under Locations, but it's not able to enumerate it (there is a spinner for some time and then it fails with an error).

FakeProvider inherits from NSObject and implements NSFileProviderReplicatedExtension and NSFileProviderEnumerating protocols. The implementation just tries to log the fact of being called (both using USL and NSLog) and calls callback closures with nils whenever needed.

It looks to me that none of this logging code gets executed (I see none of this text in Console.app). What happens is that my call to signalEnumerator times out with the following error message:

Code Block
error=Optional(Error Domain=NSCocoaErrorDomain Code=4101 "Couldn’t communicate with a helper application." UserInfo={NSUnderlyingError=0x60000125c1e0 {Error Domain=NSFileProviderInternalErrorDomain Code=7 "A connection to the extension “xxxx.test-placeholders.olamakota” could not be made." UserInfo={NSLocalizedDescription=A connection to the extension “xxxx.test-placeholders.olamakota” could not be made., NSUnderlyingError=0x60000125c240 {Error Domain=NSCocoaErrorDomain Code=4097 "connection to service on pid 0 named xxxx.olamakota.apple-extension-service" UserInfo={NSDebugDescription=connection to service on pid 0 named xxxx.test-placeholders.olamakota.apple-extension-service}}}}})


additionally there is a lot of system.log entries like:

Code Block
Jan 19 10:41:44 mbpro com.apple.xpc.launchd[1] (xxxx.test-placeholders.olamakota[2324]): Extension is hanging on launch. Killing.
Jan 19 10:41:44 mbpro com.apple.xpc.launchd[1] (xxxx.test-placeholders.olamakota[2324]): Extension did not initialize in time.
Jan 19 10:41:51 mbpro com.apple.xpc.launchd[1] (com.apple.applefsplaceholder): Service only ran for 0 seconds. Pushing respawn out by 10 seconds.


Those errors suggest that there is a problem in extension initialization, but are not verbose enough to actually be of any help in finding a problem. Official documentation on creating file providers on macOS is also not helpful - it gives no hint how file provider extensions should be initialized and/or registered in the system.

Did anyone had successfully developed a file provider extension for a Mac? Have you got to the point when the code in your extensions gets executed?

Also maybe you can share some ideas on how to debug this situation?

Accepted Reply

If your are using Swift, then you must also include module name when you specify the principal class in the info.plist like this:

Code Block
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).FileProvider</string>


I also did what you described above and it works for me: https://developer.apple.com/forums/thread/122351?answerId=645095022#645095022

Replies

If your are using Swift, then you must also include module name when you specify the principal class in the info.plist like this:

Code Block
<key>NSExtensionPrincipalClass</key>
<string>$(PRODUCT_MODULE_NAME).FileProvider</string>


I also did what you described above and it works for me: https://developer.apple.com/forums/thread/122351?answerId=645095022#645095022
Thanks for your response, Laszlo and confirming that the approach is correct. This actually helped me to get some progress.
I would like to point out that Xcode 11.5 beta 3 ships with a template for file provider extensions on macOS. As described in my own question, I did not succeed yet in getting it running, though.
Post not yet marked as solved Up vote reply of P13N Down vote reply of P13N
The template for file provider extensions is now also shipped as part of the official Xcode 12.5 release.