Please send this bug to NSUbiquitousKeyValueStore (whaaa???)

I’m getting this very weird error (send this bug to NSUKVS) when trying to get data from my app into both a lock-screen widget and an Apple Watch app.

Most documentation and online tutorials suggest using App Groups and UserDefaults(suiteName:). I have implemented this and can write to and read from my iOS app to UserDefaults(suiteName:) - no problem.

However, despite the fact that the UserDefaults(suiteName:) is found on both the lock-screen widget and the Apple Watch app - there is never any data found within.

One month ago, Eskimo posted (https://developer.apple.com/forums/thread/710966) that the UserDefaults won’t work in modern devices because the WatchOS app won’t run in an extension on the phone, so we need to use another device-to-device mechanism.

OK, so hoping that one solution will work for both targets, I built a tiny app that intends to implement NSUbiquitousKeyValueStore. (Please note that I have added the iCloud Key-value storage entitlement to the app target.)

Import SwiftUI

struct ContentView: View {
	var uks = NSUbiquitousKeyValueStore()

	var body: some View {
		Text(readData()).onAppear { writeData() }
	}

	func writeData() {
		uks.set("Hello", forKey:"name")
		uks.synchronize()
	}

	func readData() -> String {
		return uks.string(forKey:"name") ?? "n/a"
	}
}

Unfortunately, I’m getting this:

2022-09-18 17:40:32.538800-0500 Widget[5717:1877533] [Connection] Error synchronizing with cloud for store <(DevID.BundleID.AppName)>: Error Domain=SyncedDefaults Code=101010 "Tried to access unknown store DevID.BundleID.AppName" UserInfo={NSLocalizedDescription=Tried to access unknown store DevID.BundleID.AppName}

2022-09-18 17:57:58.655802-0500 Widget[5727:1883819] [Connection] BUG IN KVS: Tried to access store that is unknown to the system (DevID.BundleID.AppName). Please send this bug to NSUbiquitousKeyValueStore.

Which begs the question:

just how, exactly, does one “send a bug to NSUbiquitousKeyValueStore”??? 🤣

Is this possibly a problem with my AppleID? I ask because I’m getting really weird different results from my app which is currently in the App Store - depending upon if I’ve downloaded my app from Xcode or if I’ve downloaded it from the AppStore. Just wondering if my AppleID has somehow gotten into a corrupted state because of my Promo code (StoreKit) testing…

Any and all ideas / suggestions welcomed…

Post not yet marked as solved Up vote post of CryptoKoa Down vote post of CryptoKoa
1.5k views

Accepted Reply

Hey yellow8 - I did find a solution - and it was simple. My problem was in my entitlements files for the iCloud Key-Value Store. I needed to ensure that there was no “.” between the $(TeamIdentyifierPrefix) and my bundle identifier. So, in both the App.entitlements as well as the Widget.entitlements, the dict entries needed to be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.developer.ubiquity-kvstore-identifier</key>
	<string>$(TeamIdentifierPrefix)domain.myAppBundle</string>
</dict>
</plist>

Previously (and incorrectly), the value would have been this:

	<string>$(TeamIdentifierPrefix).domain.myAppBundle</string>

Just that “.” was my headache.

  • Thank you for posting this. Unfortunately, I do not have that extra "." Must be something else.

  • There was one other little thing - Xcode automagically sets the value for the ubiquity-kvstore-identifier to be:

    <dict> <key>com.apple.developer.ubiquity-kvstore-identifier</key> <string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string> </dict>

    And I had to replace the $(CFBundleIdentifier) with the hand-coded “domain.myAppBundle”. Just another $.02

Add a Comment

Replies

Can you please file Feedback at https://feedbackassistant.apple.com and post the FB number here? Thanks!

  • Ok - FB11540247 filed 9/18 at 4:48 CST

  • Filed FB11655726 Oct 6th

Add a Comment

Did you find a solution to this?

  • Yes, yellow8 - I did. See answer below.

Add a Comment

Hey yellow8 - I did find a solution - and it was simple. My problem was in my entitlements files for the iCloud Key-Value Store. I needed to ensure that there was no “.” between the $(TeamIdentyifierPrefix) and my bundle identifier. So, in both the App.entitlements as well as the Widget.entitlements, the dict entries needed to be:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
	<key>com.apple.developer.ubiquity-kvstore-identifier</key>
	<string>$(TeamIdentifierPrefix)domain.myAppBundle</string>
</dict>
</plist>

Previously (and incorrectly), the value would have been this:

	<string>$(TeamIdentifierPrefix).domain.myAppBundle</string>

Just that “.” was my headache.

  • Thank you for posting this. Unfortunately, I do not have that extra "." Must be something else.

  • There was one other little thing - Xcode automagically sets the value for the ubiquity-kvstore-identifier to be:

    <dict> <key>com.apple.developer.ubiquity-kvstore-identifier</key> <string>$(TeamIdentifierPrefix)$(CFBundleIdentifier)</string> </dict>

    And I had to replace the $(CFBundleIdentifier) with the hand-coded “domain.myAppBundle”. Just another $.02

Add a Comment

Clean build + restart iPad solved the issue for me

  • Restart of the iPhone (clean build) worked for me also Xcode 14.3 / iOS 16.4.1.

  • No clean build, just a restart for me.

Add a Comment