I've edited my answer. Previously, it spoke about the inability to use App Groups to sync data in watchOS 2, but your specific question is regarding the Settings Bundle, which still syncs from iOS to Apple Watch in watchOS 2.
I am unable to get this to work in Xcode 7.1 / 7.2 in Simulator, but it does work on a real device. From the docs:
Preferences in watchOS 2 are forwarded from iOS to Apple Watch, but any modifications you make are not sent back to iOS. In watchOS 1, WatchKit extensions have direct access to the defaults database and may read and write values.
All 3 targets should have the same App Group configured (the Watch App target here seems to be the missing component in OPs question):
My settings bundle:
Some simple interface code in InterfaceController.swift
:
@IBOutlet var label: WKInterfaceLabel!
@IBAction func buttonAction() {
let sharedDefaults = NSUserDefaults.init(suiteName: "group.testSettings")
let name_preference = String(sharedDefaults?.objectForKey("name_preference"))
self.label.setText(name_preference)
}
and the final outcome:
So, it does work as expected, only not in Simulator. It seems that there is some isolation occurring between the 2 devices in Simulator, and it's a little frustrating trying to put my finger on exactly what's happening there.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…