Share extension with App Group: UserDefaults don't get persisted on iOS

I have a multiplatform app for Mac and iOS, for which I am implementing a share extension. This share extension has to share settings with the app itself on both platforms. I am currently trying to achieve this by adding all targets to the same App Group and using UserDefaults with the App Group as suiteName.

The app consists of three targets: A multiplatform SwiftUI app, an iOS Share Extension, and a macOS Share Extension,.

Settings get persisted correctly on Mac and on the iOS 26 simulator. However, on a real iOS 26 beta 3 device, the Share Extension is unable to load UserDefaults (loading anything with the App Group as a suite name returns nil).

What could cause this behavior?

The following log entries are generated from the Share Extension on the iOS device, but not on the iOS simulator:

Couldn't read values in CFPrefsPlistSource<0x1030d3c80> (Domain: MY_APP_GROUP, User: kCFPreferencesAnyUser, ByHost: Yes, Container: (null), Contents Need Refresh: Yes): Using kCFPreferencesAnyUser with a container is only allowed for System Containers, detaching from cfprefsd
59638328 Plugin query method called
(501) Invalidation handler invoked, clearing connection
(501) personaAttributesForPersonaType for type:0 failed with error Error Domain=NSCocoaErrorDomain Code=4099 "The connection to service named com.apple.mobile.usermanagerd.xpc was invalidated from this process." UserInfo={NSDebugDescription=The connection to service named com.apple.mobile.usermanagerd.xpc was invalidated from this process.}
LaunchServices: store (null) or url (null) was nil: Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={_LSLine=72, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler, _LSFile=LSDReadService.mm, NSDebugDescription=process may not map database}
Attempt to map database failed: permission was denied. This attempt will not be retried.
Failed to initialize client context with error Error Domain=NSOSStatusErrorDomain Code=-54 "process may not map database" UserInfo={_LSLine=72, _LSFunction=_LSServer_GetServerStoreForConnectionWithCompletionHandler, _LSFile=LSDReadService.mm, NSDebugDescription=process may not map database}
[C:1-3] Error received: Invalidated by remote connection.

Those log messages look like log noise. Specifically, the first one, the one referencing CFPrefsPlistSource, is something that I see all the time and isn’t a sign of an actual problem.

As to what’s going wrong here, it’s hard to say. Let’s start with a simple test:

  1. In both your app and your share extension…
  2. Add some code that calls the containerURL(forSecurityApplicationGroupIdentifier:) method, passing in the same app group ID that you’re using as your suite name in UserDefaults.
  3. And then logs the resulting URL.

Do both programs log the same URL?

Share and Enjoy

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

Share extension with App Group: UserDefaults don't get persisted on iOS
 
 
Q