In iOS 16 beta 3, my iOS app sets some strings in the shared user defaults of the app group. The iOS widget extension reads the strings from the shared user defaults correctly, but the watchOS app and watchOS widget extension could not read them (get nil
). Integers stored in the shared user defaults can be read everywhere. All targets are in the same app group. Does anyone have similar problems?
It's new code.
On modern systems your watchOS code runs on the watch, meaning that you can’t share state between it and the containing iPhone app using user defaults [1]. If you want to share state like this, do that as you would in any other device-to-device situation, for example:
-
iCloud key-value store (
NSUbiquitousKeyValueStore
) -
Watch Connectivity
-
CloudKit
-
Third-party cloud platforms
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Way back in the day part of your watchOS app, the WatchKit app extension, did run the iPhone, but that hasn’t been the case for years.