如何在 macOS 上检索文件提供程序扩展的 XPC 服务?
How to retrieve the XPC service of a file provider extension on macOS?
我延长了my example project from with an attempt to establish an XPC connection.
在另一个项目中,我们已经成功地实现了 iOS 的文件提供程序。暴露的服务必须由它负责的 URL 来解析。在 iOS 上这是唯一的可能性,在 macOS 上也是如此。因为在 macOS 上,系统负责管理文件,所以没有 URL,除了可以通过 NSFileProviderItemIdentifier.rootContainer
.
解析的 URL
在 the AppDelegate.didFinishLaunching()
method 中,我尝试像这样检索服务(请参阅链接代码以获取完整参考,我暂时不想不必要地膨胀这个问题页面):
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 extension is creating a service source on initialization which creates an NSXPCListener
which has an NSXPCListenerDelegate
that exports the NSFileProviderReplicatedExtension
object on new connections。我错过了什么?
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
}
可疑:serviceName
of the FileProviderServiceSource
never is queried。我们不知道为什么这不起作用。
有一个您的扩展程序的主体 class 可以实现的协议,NSFileProviderServicing。
https://developer.apple.com/documentation/fileprovider/nsfileproviderservicing
我延长了my example project from
在另一个项目中,我们已经成功地实现了 iOS 的文件提供程序。暴露的服务必须由它负责的 URL 来解析。在 iOS 上这是唯一的可能性,在 macOS 上也是如此。因为在 macOS 上,系统负责管理文件,所以没有 URL,除了可以通过 NSFileProviderItemIdentifier.rootContainer
.
在 the AppDelegate.didFinishLaunching()
method 中,我尝试像这样检索服务(请参阅链接代码以获取完整参考,我暂时不想不必要地膨胀这个问题页面):
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 extension is creating a service source on initialization which creates an NSXPCListener
which has an NSXPCListenerDelegate
that exports the NSFileProviderReplicatedExtension
object on new connections。我错过了什么?
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
}
可疑:serviceName
of the FileProviderServiceSource
never is queried。我们不知道为什么这不起作用。
有一个您的扩展程序的主体 class 可以实现的协议,NSFileProviderServicing。
https://developer.apple.com/documentation/fileprovider/nsfileproviderservicing