我创建了一个 XPC 服务。
服务器端代码简要地是
NSXPCListener *listener = [[NSXPCListener alloc] initWithMachServiceName:@"test.xpcserver"];
listener.delegate = delegate;
[listener resume];
这是使用 info.plist 作为启动代理安装的
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>TestServer</string>
<key>MachServices</key>
<dict>
<key>test.xpcserver</key>
<true/>
</dict>
<key>ProgramArguments</key>
<array>
<string>/Applications/test.app/Contents/XPCServices/xpcserver.xpc/Contents/MacOS/xpcserver</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
服务器运行良好,我可以看到它使用launchctl list运行
客户端代码在另一个应用程序中,连接代码是:
connection = [[NSXPCConnection alloc] initWithMachServiceName:@“test.xpcserver” options:0];
connection.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(xpcserverprotocol)];
[connection resume];
service = [connection remoteObjectProxyWithErrorHandler:^(NSError * _Nonnull error) { }];
[service ServerFunc:@“howdy” withReply:^(NSString *result) {
NSLog(@"%@",result);
}];
但无法连接到服务器。关于出了什么问题的任何指示?