【发布时间】:2014-10-10 05:44:03
【问题描述】:
我正在XPCServices 上尝试一个简单的示例应用程序,我在其中执行以下步骤:
第 1 步: 创建一个示例项目并添加目标 - XPCServices 和名称 - HelperProcess。创建目标时,XCode 会自动生成以下文件:
- HelperProcessProtocol.h
- HelperProcess.h
- HelperProcess.m
- 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;
}
第 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: 显示也不显示助手 进程出现在活动监视器中:(
这里是代码: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 步: 更新 - 主应用目标 -> 功能选项卡
- 开启“应用沙盒”
- 开启“应用组”
- 添加了一个应用组 - 'XYZ'
第 2 步: 更新 - Helper Target -> Capabilities Tab
- 开启“应用沙盒”
- 启用“传出连接(客户端)”
- 开启“应用组”
- 添加了一个应用组 - '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 服务示例应用程序正常工作?
【问题讨论】:
-
这很奇怪,但对我来说,当我将捆绑标识符从“XYZ”更改为 com.
. 时它突然起作用了 -
这真的很奇怪 :-|但我会试一试,谢谢伙计:) 如果它有效,你可以将它作为答案发布,一旦验证,我会将其标记为接受的答案:)
-
@Anno2001 由于某些原因它仍然无法工作:(你能分享对你有用的代码吗?
-
您好,虽然您发布问题可能已经过去了很长时间,但是如果您有任何问题,也许您可以分享一个解决方案?我目前正在为类似的情况而苦苦挣扎。谢谢!
标签: objective-c macos cocoa xcode6 nsxpcconnection