UserDefaults and @AppStorage causing DeviceActivityMonitor to crash on iOS 17

I use App Groups to share UserDefaults data between my host app and DeviceActivityMonitor extension.

On iOS 17, it appears that reading @AppStorage variables are causing my DeviceActivityMonitor extension callback functions to crash. Weirdly, writing values is okay.

I see this in the extension logs:

Couldn't read values in CFPrefsPlistSource<0x10fe251d0> (Domain: GROUP_NAME, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd

However, through searching this log message on the internet and the fact that it also appears in my host app logs without crashing, this seems to be a warning - possibly indicating an issue but also a possible red herring.

But the fact remains that when I don't read UserDefaults values or variables decorated with @AppStorage in the DeviceActivityMonitor extension, everything works fine.

Are UserDefaults, and specifically @AppStorage decorators supported in the DeviceActivityMonitor extension?

Replies

Thank you for sharing this issue. I will attempt to reproduce it when I have time. Does the problem occur on all versions of iOS 17, or did it start with a specific version (e.g., 17.2)? Have you filed a bug report with Apple regarding this?

  • I have not. My experience with Feedback Assistant has been poor, none of my bug reports ever get any replies. I simply avoided using @AppStorage variables in the DeviceActivityMonitor extension functions. This seemed to help at first, but have started breaking again with the release of iOS 17.2 without the use @AppStorage. I suspect it may be caused by any use of User Defaults at all. How does your app read / write data in the extensions?

Add a Comment