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

后端 未结 5 790
Happy的楠姐
Happy的楠姐 2021-02-09 05:26

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 funct

5条回答
  •  失恋的感觉
    2021-02-09 05:41

    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

提交回复
热议问题