I created a macOS app, added an XPC service target, and also added a source editor extension.
in The source editor extension‘s perform function. It doesn't work
- (void)performCommandWithInvocation:(XCSourceEditorCommandInvocation *)invocation completionHandler:(void (^)(NSError * _Nullable nilOrError))completionHandler {
self.xpcConnect = [[NSXPCConnection alloc] initWithServiceName:@"test.TestNewXPCApp.NewXPC"];
NSXPCInterface *interface = [NSXPCInterface interfaceWithProtocol:@protocol(NewXPCProtocol)];
self.xpcConnect.remoteObjectInterface = interface;
[self.xpcConnect resume];
[[self.xpcConnect remoteObjectProxy] performCalculationWithNumber:@231 andNumber:@119 withReply:^(NSNumber *reply) {
// We have received a response.
NSLog(@"ui success%@", reply);
}];
But In ViewControler.m, executing the same code , it can work.
So why is it possible to connect to the XPC service from within the macOS app, but not from the source editor extension?
XPC services are scoped to the app in which they’re embedded. So, if you have the XPC service embedded in your app, then your app can ‘see’ it but your appex cannot.
If you want the appex to see your XPC service, embed that XPC service in your appex.
If you want your app and appex to connect to the same XPC service, that’s challenging. Let me know if that’s the case and I can talk you through your options.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"