Search code examples
iosiphonewatchkitapple-watch

How to establish a communication channel between Apple Watch Extension/App and iOS App


I'm exploring the WatchKit SDK.

When I have a WatchKit app, is it possible to set values (e.g. Text, settings) from the iPhone app on the WatchKit app? Can I call functions in the WatchKit app extension from the iPhone app?

If someone managed to do this, could he/she post an example? Thanks!


Solution

  • You can use App Group and sharedDefaults to share data between the WatchApp/Extension and the App on the phone. see example: WatchKit SDK not retrieving data from NSUserDefaults

    Study up on iOS8 Extension/App Groups/sharedDefaults and watchkit extension will make more sense.

    This sample takes a UIImage from Shinobi chart, save it to defaults as image. Then extension picks up the image through defaults and shows it on watch

    https://github.com/ChrisGrant/ChartWatch

    This one uses multipeer connectivity to have watch talk to phone.

    https://github.com/jsclayton/swatches

    but this uses Bluetooth and I presume the Watch OS also communicates to the phone using bluetooth so not sure if they'll both be allowed.

    We have no devices to test on yet so the /swatches app is just watch simuator talking to iphone simulator on same mac.

    If youve ever done low level AV programming you know the app may run on the simulator but fail on the device because the simulator can cheat an use Mac OSX media layer. May be the same for bluetooth.

    other samples

    https://github.com/search?q=WKInterfaceController&type=Code