MacCatalyst - How to share Userdefaults between widget and app

Hi,

Firstly: The whole question is about MacCatalyst (in IOS it works as intended)

In my Maccatalyst app I want to share Userdefaults between app and widget. I have added an app group to the widget and the app and have set up Userdefauls accordingly.

Here is the problem:

Xcode claims that the app group should start with "group.***" because Catalyst is based on iOS. If I do so, my Catalyst app rises the "App wants to access data from other apps" requester on EVERY launch. So, I can't use it in production. Even if I would accept the requester, the widget isn't able to access the defaults at all because it does not rise that requester, but silently ignores the access.

In contrast, if I setup the app group name with our TeamID (instead of group.*) then the requester vanishes, but Xcode does not accept it, issuing a warning and displaying the app group in red. I don't think this is advisable 'state' for production code. Even then widget can't see the data either.

What is the recommended way of sharing Userdefaults between Catalyst app and Catalyst Widget (not the iOS widget which displays the "open on iPhone warning" when clicked) on macOS ?

Thanks

Answered by DTS Engineer in 813262022

Using a group. prefix is fine in a Mac Catalyst app.

If you’re interesting in the long and complex backstory to this, see App Groups: macOS vs iOS: Fight!

Share and Enjoy

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

Using a group. prefix is fine in a Mac Catalyst app.

If you’re interesting in the long and complex backstory to this, see App Groups: macOS vs iOS: Fight!

Share and Enjoy

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

Using a group. prefix is fine in a Mac Catalyst app.

Thanks for your feedback. I tried this, but there are 2 issues.

  1. If I use group.* I get this annoying requester at every launch of the catalyst app (I am running macOS 15.1), and

  2. the widget isn't able to access Userdefaults. The widget comes up always with default settings despite what is set in Userdefaults. I don't know why ... (in iOS it works).

Accepted Answer

I found the issue. For some reason the provisioning file for Catalyst was not correctly updated when adding the app group. After deleting the Xcode managed profiles and rebuilding them the app group entitlement also appeared for the Catalyst app and the requester is gone. Thanks for your response anyway !

MacCatalyst - How to share Userdefaults between widget and app
 
 
Q