Dear all,
Since It is my first apple watch application I just realized that is not possible to use AppGroups to sync between devices and after I spent 5 days in debugging something impossible to do 🙁 ...
... I am now trying to sync between iPhone and AppleWatch using iCloud (CloudKit), SwiftData and the following code (on iOS 17 and Watch OS 10 - beta 3):
My Persistency Library
public let fullSchema: Schema = Schema([
SWDItem.self,
SWDPackage.self
])
public func makeContainer() -> ModelContainer {
let configuration = ModelConfiguration(
"SWDMyApp",
schema: fullSchema,
sharedAppContainerIdentifier: "my.appgroup.id",
cloudKitContainerIdentifier: "iCloud.my.icloud.id")
return try! ModelContainer(for: fullSchema, configuration)
}
And at the start of the app there is the following configuration as described in SwiftData documentation:
iOS/iPad OS
@main
struct MyApp: App {
let container = SWDModelContainer().makeContainer()
[...]
var body: some Scene {
WindowGroup {
LaunchScreen()
}
.modelContainer(container)
}
And the same for AppleWatch
Watch OS 10
@main
struct MyAppWatch: App {
let container = SWDModelContainer().makeContainer()
var body: some Scene {
WindowGroup {
ContentView()
}
.modelContainer(container)
}
}
The model configuration is defined in a Swift Package. Therefore the code to configure the model container is exactly the same.
The app works perfectly and can store data successfully. Data are persisted.
The iCloud sync works between my iPad and my iPhone, BUT NOTHING ARRIVES TO APPLE WATCH.
- The entitlements of the applewatch is the following:
Where iCloud container and AppGroup container match the iOS ones.
- I am logged in with the same iCloud account in all devices
- The watch is connected to WiFi
Why the SwiftData sync does not work on AppleWatch? What else can I check to make it work?
Thanks a lot in advance for your help