Is it possible to share an app group between Catalyst and AppKit Apps?

I have 2 Apps.

  1. A sandboxed native Mac App written in AppKit/SwiftUI.
  2. A Catalyst App.

I would like them to be able to communicate with each other. I assumed I would be able to do this using a shared App Group but I can't get it to work and I think this is because the App Group naming conventions appear to be different.

As far as I can make out:

  • A Mac App uses App groups prefixed with the team ID
  • A Catalyst App uses the iOS App groups which are prefixed with group.

I have tried multiple combinations of different prefixes to try and make this work but without success.

I have been "testing" this by using UserDefaults(suiteName: appGroup) and then attempting to read write values between the 2 Apps but without success so far.

My questions are:

  1. Is sharing an App Group between Catalyst and native technically possible?
  2. If it is possible what is the magic combo of App Group prefixes that makes it work?
  3. If it is not possible then do I have any other options for communicating between a sandboxed Mac App and a Catalyst App?
Answered by DTS Engineer in 718521022

Is sharing an App Group between Catalyst and native technically possible?

Yes.

If it is possible what is the magic combo of App Group prefixes that makes it work?

Use the Developer website to create an iOS-style App Group — that is, group.UUU where UUU is unique — in your team and then use that app group ID in both apps.

Add that group to the com.apple.security.application-groups entitlement to both apps.

On macOS this entitlement does not need to be authorised by a provisioning profile. That checking is deferred until you submit your app to the Mac App Store.

IMPORTANT If you’re using Xcode, be aware that it really wants to add your Team ID as a prefix to your app group ID. Dump the entitlements of both apps to make sure that hasn’t happened:

% codesign -d --entitlements - /path/to/your.app

I have a to-do list item to update the app groups docs to cover this (r. 92322409). It is, alas, a very long to-do list )-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

Is sharing an App Group between Catalyst and native technically possible?

Yes.

If it is possible what is the magic combo of App Group prefixes that makes it work?

Use the Developer website to create an iOS-style App Group — that is, group.UUU where UUU is unique — in your team and then use that app group ID in both apps.

Add that group to the com.apple.security.application-groups entitlement to both apps.

On macOS this entitlement does not need to be authorised by a provisioning profile. That checking is deferred until you submit your app to the Mac App Store.

IMPORTANT If you’re using Xcode, be aware that it really wants to add your Team ID as a prefix to your app group ID. Dump the entitlements of both apps to make sure that hasn’t happened:

% codesign -d --entitlements - /path/to/your.app

I have a to-do list item to update the app groups docs to cover this (r. 92322409). It is, alas, a very long to-do list )-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Thanks Quinn, this helped me get it working.

Just to note two additional things that I found confusing in the process.

  1. The defaults command line tool doesn't really help here, as far as I can work out it can't be used with App groups. When using defaults read group.UUU myKey I get The domain/default pair of (group.UUU, myKey) does not exist Is that expected?
  2. The Mac Native side logs a scary message when trying to access values, but does in-fact seem to find the value still. Not sure how concerned I should be able this.
[User Defaults] Couldn't read values in CFPrefsPlistSource<0x600003978680> (Domain: group.UUU, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
Is it possible to share an app group between Catalyst and AppKit Apps?
 
 
Q