I am trying to add the ability to send data from iPhone to Watch. I have application groups configured and everything works smoothly, but when I try to add an observer to NSUserDefaults in the Watch Extension file, the application always crashes on startup. (And yes, I confirmed that the application group name is correct and verified in all target capabilities, and all provisioning profiles are updated with the application group enabled)
the code:
override func willActivate()
{
super.willActivate()
NSUserDefaults(suiteName: "my.suite.name")?.addObserver(self, forKeyPath: "phoneSaysHello", options: NSKeyValueObservingOptions.New, context: nil)
}
override func didDeactivate()
{
super.didDeactivate()
NSUserDefaults(suiteName: "my.suite.name")?.removeObserver(self, forKeyPath: "phoneSaysHello", context: nil)
}
Error:
*** - "NSInternalInconsistencyException", : " 0x7f99534559b0 NSUserDefaults , . : ( : 0x0, : 0x7f9953609200 > ) '