OGeek|极客世界-中国程序员成长平台

标题: ios - 使用 mach 端口的 Theos 应用间通信 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 08:52
标题: ios - 使用 mach 端口的 Theos 应用间通信

我正在尝试在 iOS 8 上的应用和控制台应用(使用 theos)之间发送数据。

我试过了:

应用程序:

CFMessagePortRef port = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("co.test"), &message_callback, NULL, NULL);

这很好用。 NSLog(@"%@", port) 返回:

{locked = Maybe,valid = Yes,remote = No,name = co.test,source = 0x0,callout = message_callback (0x1000e979c),context = }

但是,当尝试在控制台应用上执行相同操作时:

CFMessagePortRef 端口 = CFMessagePortCreateLocal(kCFAllocatorDefault, CFSTR("co.test"), &message_callback, NULL, NULL);

我总是得到错误:

*** CFMessagePort: bootstrap_register(): failed 1100 (0x44c) 'ermission denied', port = 0xc03, name = 'co.test'

即使我对两者都使用相同的 com.apple.security.application-groups 权利:

<key>com.apple.security.application-groups</key>
<array>
    <string>co.test</string>
</array>

任何人都可以阐明 - 也许上面是一种糟糕的方法,我错过了一种更简单的方法来实现我的目标?

我的目标是能够在 SpringBoard 上运行的应用程序和使用 theos 构建的守护程序之间传递 NSDictionary。

注意:我无意在应用商店分发此应用



Best Answer-推荐答案


Application: .......CFSTR("co.test")
Console App: ... CFSTR("co.test")

您需要在应用程序组标识符的末尾附加一个附加字符串。

Apple:

Mach port names must begin with the application group identifier, followed by a period (.), followed by a name of your choosing.

For example, if your application group’s name is Z123456789.com.example.app-group, you might create a Mach port named Z123456789.com.example.app-group.Port_of_Kobe.

CFMessagePort and sandboxing

如果您使用相同的消息端口名称创建多个消息端口,似乎会发生另一次崩溃。可能来自具有相同捆绑 ID 的应用程序或其他一些应该只有一个消息端口并且已经在运行的情况。

当我从 /Applications/ 运行我的 macOS 应用程序的一个版本并通过 Xcode 运行另一个版本时,我注意到了这一点。

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

关于ios - 使用 mach 端口的 Theos 应用间通信,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31182144/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4