I am creating a WatchKit app and was wondering how to send a message/data from the iPhone to the Watch?
I know how to do it the other way around (watch -> phone) using 'openParentApplication:reply:' and 'application:handleWatchKitExtensionRequest:reply:' but can't find any documentation on how to communicate from phone to watch.
Simple setup would be the iPhone app has a button that when pressed should update a label on the Watch app.
Can anyone point me in the right direction?
First, you have to enable app groups for your target:
Then you can start to write and read objects via NSUserDefaults
:
// write
let sharedDefaults = NSUserDefaults(suiteName: appGroupName)
sharedDefaults?.setInteger(1, forKey: "myIntKey")
// read
let sharedDefaults = NSUserDefaults(suiteName: appGroupName)
let myIntValue = sharedDefaults?.integerForKey("myIntKey")
See the chapter Sharing Data with Your Containing iOS App in Apple Watch Programming Guide: Developing for Apple Watch
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