XPCService没有从应用程序启动

Dev*_*shi 6 macos cocoa objective-c nsxpcconnection xcode6

我正在尝试一个简单的示例应用程序XPCServices,其中我遵循以下步骤:

第1步:创建一个示例项目并添加目标 - XPCServices名称 - HelperProcess.创建目标时,XCode会自动生成以下文件:

  1. HelperProcessProtocol.h
  2. HelperProcess.h
  3. HelperProcess.m
  4. 的main.m

第2步:在实现中main.m添加了一个日志语句ServiceDelegate:

- (BOOL)listener:(NSXPCListener *)listener shouldAcceptNewConnection:(NSXPCConnection *)newConnection {
    // This method is where the NSXPCListener configures, accepts, and resumes a new incoming NSXPCConnection.
    NSLog(@"Log which is never displayed :(");
    // Configure the connection.
    // First, set the interface that the exported object implements.
    newConnection.exportedInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)];

    // Next, set the object that the connection exports. All messages sent on the connection to this service will be sent to the exported object to handle. The connection retains the exported object.
    HelperProcess *exportedObject = [HelperProcess new];
    newConnection.exportedObject = exportedObject;

    // Resuming the connection allows the system to deliver more incoming messages.
    [newConnection resume];

    // Returning YES from this method tells the system that you have accepted this connection. If you want to reject the connection for some reason, call -invalidate on the connection and return NO.
    return YES;
}
Run Code Online (Sandbox Code Playgroud)

步骤3:AppDelegate加入下面的代码在applicationDidFinishLaunching:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
    // Insert code here to initialize your application

    _connectionToService = [[NSXPCConnection alloc] initWithServiceName:@"HelperProcess"];
    _connectionToService.remoteObjectInterface = [NSXPCInterface interfaceWithProtocol:@protocol(HelperProcessProtocol)];
    [_connectionToService resume];
}
Run Code Online (Sandbox Code Playgroud)

问题是 -

当我启动应用程序时,既没有在监听器中添加日志:shouldAcceptNewConnection:也没有显示助手进程在活动监视器中:(

这是代码:XPCShootOut

注意:我在XCode 6.0上尝试这个

是否有任何其他设置可以让它工作?请建议.

- 更新 -

我试图从apple中引用这个示例:AppSandboxLoginItemXPCDemo

当我尝试在XCode 6上运行它时,它显示错误消息 - "未找到签名身份".由于我没有注册的mac开发者帐户,在iDecide和iDecideHelper的构建设置中,我将"代码签名身份"更改为"不代码签名".

我收到了每个目标的警告:

Code Sign warning: CODE_SIGN_ENTITLEMENTS specified without specifying CODE_SIGN_IDENTITY. It is not possible to add entitlements to a binary without signing it.
Run Code Online (Sandbox Code Playgroud)

这次我编译构建时,它按预期工作.

现在我尝试按照其ReadMe.txt文件中指定的步骤进行操作,特别是我在示例应用程序中执行了以下步骤:

第1步:更新 - 主应用程序目标 - >功能选项卡

  1. 打开'App Sandbox'
  2. 打开'App Groups'
  3. 添加了一个应用程序组 - 'XYZ'

第2步:更新 - 帮助目标 - >功能选项卡

  1. 打开'App Sandbox'
  2. 启用"传出连接(客户端)"
  3. 打开'App Groups'
  4. 添加了一个应用程序组 - 'XYZ'

第3步:更新 - 帮助目标 - >常规选项卡 - >捆绑标识符,为其添加了"XYZ"前缀.

在控制台中运行应用程序时,它显示以下消息:

10/12/14 6:27:42.159 PM xpcd[554]: (null): Code identity[pid: 11875::Devarshi-Kulshreshtha.XPCShootOut (/Users/devarshi/Library/Developer/Xcode/DerivedData/XPCShootOut-aaedwraccpinnndivoaqkujcmhmj/Build/Products/Debug/XPCShootOut.app)] is not in ACL for container: ~/Library/Containers/Devarshi-Kulshreshtha.XPCShootOut/Data -- allowing access.

10/12/14 6:27:43.712 PM appleeventsd[63]: <rdar://problem/11489077> A sandboxed application with pid 11875, "XPCShootOut" checked in with appleeventsd, but its code signature could not be validated ( either because it was corrupt, or could not be read by appleeventsd ) and so it cannot receive AppleEvents targeted by name, bundle id, or signature. Error=ERROR: #100013  { "NSDescription"="SecCodeCopySigningInformation() returned 100013, -." }  (handleMessage()/appleEventsD.cp #2072) client-reqs-q
Run Code Online (Sandbox Code Playgroud)

这两个应用程序都没有执行其预期的功能,也没有显示在listener:shouldAcceptNewConnection:委托中添加的日志消息.

我很无能为力.如果我遗失任何东西,请建议吗?是否可以在没有注册的mac开发者帐户的情况下使XPC服务示例应用程序正常工作?

小智 -2

我认为您不能在没有签名的情况下启动 XPC 服务。

即使为了测试和调试,也需要设置代码签名构建基础设施。

我认为 Mac 开发者证书是免费的,您不需要付费帐户。