Home > Mobile >  How to retrieve the XPC service of a file provider extension on macOS?
How to retrieve the XPC service of a file provider extension on macOS?

Time:11-13

I have extended my example project from my previous question with an attempt to establish an XPC connection.

In a different project we have successfully implemented the file provider for iOS. The exposed service must be resolved by URLs it is responsible for. On iOS it is the only possibility and on macOS it appears like that, too. Because on macOS the system takes care of managing files there are no URLs except the one which can be resolved through NSFileProviderItemIdentifier.rootContainer.

In the AppDelegate.didFinishLaunching() method I try to retrieve the service like this (see linked code for full reference, I do not want to unnecessarily bloat this question page for now):

let fileManager = FileManager.default
        let fileProviderManager = NSFileProviderManager(for: domain)!
        
        fileProviderManager.getUserVisibleURL(for: NSFileProviderItemIdentifier.rootContainer) { url, error in
            // [...]

            fileManager.getFileProviderServicesForItem(at: url) { list, error in
                // list always contains 0 items!
            }
        }

The delivered list always is empty. However the extension is creating a service source on initialization which creates an NSXPCListener which has an NSXPCListenerDelegate that exports the NSFileProviderReplicatedExtension object on new connections. What am I missing?

func listener(_ listener: NSXPCListener, shouldAcceptNewConnection newConnection: NSXPCConnection) -> Bool {
        os_log("XPC listener delegate should accept new connection...")

        newConnection.exportedObject = fileProviderExtension
        newConnection.exportedInterface = NSXPCInterface(with: SomeProviderServiceInterface.self)
        newConnection.remoteObjectInterface = NSXPCInterface(with: SomeProductServiceInterface.self)
        newConnection.resume()

        return true
    }

Suspicious: serviceName of the FileProviderServiceSource never is queried. We are out of ideas why this is not working.

CodePudding user response:

There is a protocol which your extension's principal class can implement, NSFileProviderServicing.

https://developer.apple.com/documentation/fileprovider/nsfileproviderservicing

  • Related