I have set up App Groups and am using NSUserDefaults initWith suiteName
in order to allow my app and my extension to access the same set of preferences. I would now like to replace that implementation with one that will sync those preferences over iCloud (if they have iCloud enabled).
I have read up on on NSUbiquitousKeyValueStore
which seems to be exactly what I need. However, the documentation states "An app must always use the default iCloud key-value store object to get and set values. This store is tied to the unique identifier string your app provides in its entitlement requests." That causes me to believe if I adopt this, the app extension won't be accessing the same store as the main app. Nothing was said in the Extensions Programming Guide about sharing such a store, it only mentioned a solution that allows access to the same preferences but only stored locally on that device.
How would one implement iCloud synchronization of simple preferences that can also be accessed from that app's extensions?
Another quick question, has anything changed for iOS 8? I know major changes have come in regards to iCloud API but perhaps they didn't touch the simple preferences syncing, only implemented iCloud Drive?
I recently encounter the same issue, I share my solution here, hopefully it can help someone.
com.apple.developer.ubiquity-kvstore-identifier
must be same between main app and extension app.
If you create an extension app (today extension), you will have 2 .entitlements
files, one is for main app, the other one is for extension app.
You can find the value of com.apple.developer.ubiquity-kvstore-identifier
from both .entitlments
files. You need to make sure both values are same.
I was using $(TeamIdentifierPrefix)$(CFBundleIdentifier)
for both .entitlements
files, which is wrong. Because $(CFBundleIdentifier)
is bundle id, it's actually different value for main app and extension app.
The fix is using hard coded bundle id: $(TeamIdentifierPrefix)com.youcompnay.app
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With