5

我正在调整 MacOS 应用程序以使用沙盒。当我尝试在控制台中使用“拒绝 mach-lookup”消息调用 CFMessagePortCreateRemote 时,它​​使用了一个帮助应用程序(同一包中的一个 exe),该应用程序失败。

我可以看到com.apple.security.temporary-exception.mach-lookup.global-name授权密钥可以解决这个问题,但这只是暂时的。

有没有办法在沙盒应用程序中使用 mach 端口实现两个应用程序之间的通信?

错误:

let port = CFMessagePortCreateLocal(nil, "XXXYYYZZZZ.MyAppGroupName" as CFString, Callback, nil, nil)
let runLoopSource = CFMessagePortCreateRunLoopSource(kCFAllocatorDefault, port, 0)
CFRunLoopAddSource(CFRunLoopGetCurrent(), runLoopSource, .commonModes)

*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', 端口 = 0x14807, name = 'XXXYYYZZZZ.MyAppGroupName'

4

2 回答 2

5

对于目标 app 和 helper exe :

  • 启用沙盒
  • 添加一个以您的 teamid 为前缀的公共组

    Z123456789.com.example.app-group

使用您的 teamID ex 命名您的 mach 端口:

Z123456789.com.example.app-group.Port_of_Kobe

苹果文档链接

于 2017-03-08T23:11:18.447 回答
0

在. CFMessagePortCreateRunLoopSource_ CFStringRef name_CFMessagePortCreateLocal

我使用的是我的应用程序组的名称,XXXYYYZZZZ.MyAppGroupName.

在阅读了 Apple 文档后,我将其更改为,XXXYYYZZZZ.MyAppGroupName.someOtherString并且崩溃消失了。

Mach 端口名称必须以应用程序组标识符开头,后跟句点 (.),然后是您选择的名称。

例如,如果您的应用程序组的名称是Z123456789.com.example.app-group,您可能会创建一个名为 的 Mach 端口Z123456789.com.example.app-group.Port_of_Kobe

https://developer.apple.com/library/archive/documentation/Security/Conceptual/AppSandboxDesignGuide/AppSandboxInDepth/AppSandboxInDepth.html#//apple_ref/doc/uid/TP40011183-CH3-SW24

编辑:

第二天早上,我试图运行相同的代码。这一次,我遇到了与我昨晚使用相同附件的崩溃。".someOtherString"如果我更改为其他字符串,它工作正常。这令人沮丧,因为我不知道该字符串何时/如何变得无效。

线程 1:EXC_BAD_ACCESS(代码=1,地址=0x8)

*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'Permission denied', port = 0xcd07, name = 'XXXYYYZZZZ.MyAppGroupName.someOtherString'

编辑2:

我再次撞到了崩溃,这次是用新的字符串。/Applications/除了我的 Xcode 构建文件夹中的版本之外,该问题可能与从文件夹中运行应用程序版本有关。

端口名称在当前用户上下文中通常应该是唯一的;否则,您可能会遇到冲突。

https://developer.apple.com/library/archive/documentation/Cocoa/Conceptual/Multithreading/RunLoopManagement/RunLoopManagement.html

于 2018-10-19T05:07:00.857 回答