I'm building a sandboxed macOS app with Swift, which contains a child app inside.
What I want to implement is:
- Parent can launch multiple child apps
- Parent send different content to each child app to show
- Both parent and child app have their own UIs.
Implementation way I've been thinking about:
Distributed Notification
Distributed notification with user info objects are denied by sandbox.
CFMessagePort
It requires both parent and child app are in the same app group, and signed with proper provision profiles. But on Xcode it is always None required
on the provision profile settings so nowhere to change the settings.
Besides, there is no documents or posts explaining how to use CFMessagePort in Swift. I tried the code below but it crashes everytime as it's denied by sandbox.
let portName = "{team_identifier}.{app_group_identifier}.{port_name}"
let remote = CFMessagePortCreateRemote(nil, portName as CFString)
var returnData: Unmanaged<CFData>? = nil
if kCFMessagePortSuccess == CFMessagePortSendRequest(remote, 0, data as CFData, 1, 1, CFRunLoopMode.defaultMode.rawValue, &returnData) && nil != returnData {
}
NSXPCConnection
I don`t think XPC works for this situation, as XPC is designed to communicate between a service running invisible and a client app, while the service is bundled into the app. I doubt it would work for the parent-child model.
So, is there any better way to achieve my target? I feel I should go with CFMessagePort but I also need some more help on how to use it with Swift. Thanks!