6

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

第 1 步:创建一个示例项目并向其中添加目标(XPCServices带有名称)HelperProcess。创建目标时,XCode 会自动生成以下文件:

  1. HelperProcessProtocol.h
  2. HelperProcess.h
  3. HelperProcess.m
  4. 主文件

第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;
}

第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];
}

问题是——

当我启动应用程序时,既不会显示在 listener:shouldAcceptNewConnection: 中添加的日志,也不会在 Activity Monitor 中显示 helper 进程:(

这是代码:XPCShootOut

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

是否需要进行任何其他设置才能使其正常工作?请建议。

- 更新 -

我试图从苹果引用这个示例: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.

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

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

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

  1. 打开“应用沙盒”
  2. 打开“应用程序组”
  3. 添加了一个应用组 - 'XYZ'

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

  1. 打开“应用沙盒”
  2. 启用“传出连接(客户端)”
  3. 打开“应用程序组”
  4. 添加了一个应用组 - 'XYZ'

第 3 步:更新 - Helper Target -> General Tab -> Bundle Identifier,添加“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

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

我一无所知。请建议我是否缺少任何东西?是否可以在没有注册 mac 开发者帐户的情况下使 XPC 服务示例应用程序正常工作?

4

1 回答 1

-2

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

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

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

于 2015-01-13T22:04:10.583 回答