Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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!

like image 334
cujo30227 Avatar asked Nov 26 '14 08:11

cujo30227


2 Answers

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

like image 170
brian.clear Avatar answered Oct 10 '22 06:10

brian.clear


There are several solutions: CoreData, NSKeyedUnarchiver and NSUserDefaults. With a common background for sharing the common data resource (Database, file or user default settings), this is enabling App Groups capabilities on both targets project properties.

enter image description here

In the following post is explained how to do it with default settings and you can also download the demo project.

like image 38
Javier Calatrava Llavería Avatar answered Oct 10 '22 04:10

Javier Calatrava Llavería