Xcode: 16.1 macOS: Sequoia
When I run widget preview, I got the following errors
CoreData: error: Store failed to load. <NSPersistentStoreDescription: 0x156237310> (type: SQLite, url: file:///Users/user/Library/Group%20Containers/group.com.app.name/Library/Application%20Support/default.store) with error = Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Unknown failure to access file: 1} with userInfo {
reason = "Unknown failure to access file: 1";
}
Unresolved error loading container Error Domain=NSCocoaErrorDomain Code=256 "The file couldn’t be opened." UserInfo={reason=Unknown failure to access file: 1}
with this code
let sharedModelContainer: ModelContainer = {
let schema = Schema([Company.self, Person.self])
do {
return try ModelContainer(for: schema, configurations: [.init(isStoredInMemoryOnly: false)])
} catch {
fatalError("error: \(error)")
}
}()
Does anyone know why this happens and how to fix this?
Thanks for your following up. This is indeed an issue happening on macOS 15 Sequoia. Specifically, the widget doesn't have the access to the App Group container on macOS Sequoia because the container is iOS-styled (A), as mentioned in the System Integrity Protection section of the macOS Sequoia 15 Release Notes:
" ... This restriction also applies to app extensions, although in that case the system won’t prompt the user for consent but will instead just deny the access. "
This topic is discussed in App Groups: macOS vs iOS: Fight!, but long story short:
-
The access failure isn't supposed to happen in the production environment, assuming that the iOS-style App Group container is correctly added to the App Group entitlements (
com.apple.security.application-groups
) in your macOS app and extension targets. -
To work around the access failure in the development phase, you can use a macOS-style App Group container (B) during development, and switch to the iOS-style App Group container for production.
-
If your iOS app doesn't support
Mac Catalyst
oriOS Apps on Mac
, and so doesn't share the same App Group container with your macOS app, you can choose to have your macOS app / extensions use a macOS-style App Group container, and your iOS app / extensions use an iOS-style container.
To use a different .entitlements
file for your macOS app / extension in a universal target, use CODE_SIGN_ENTITLEMENTS
to conditionalize the entitlements file build setting. Taking the TripsWidget
target in the SampleTrips
project as an example:
-
Duplicate the existing
TripsWidgetExtension.entitlements
, name itTripsWidgetExtensionMacOS.entitlements
, and add it to the project. -
Change to App Group container ID to from
group.com.example.apple-samplecode.SampleTrips
to<Your team ID>.com.example.apple-samplecode.SampleTrips
-
Use the
CODE_SIGN_ENTITLEMENTS
build setting to conditionalize the entitlements file build, as shown in the attached screenshot.
(A) An iOS-style App Group container: A container with an ID that has a group.
prefix.
(B) A macOS-style App Group container: A container with an ID that has a <TeamID>.
prefix.
Best,
——
Ziqiao Chen
Worldwide Developer Relations.