7

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!

Curiosity
  • 544
  • 1
  • 15
  • 29
cujo30227
  • 720
  • 7
  • 15
  • Seems like a broad question. Voting to close. – trojanfoe Nov 26 '14 at 08:16
  • @trojanfoe Perhaps if this was rephrased as _How to establish a communication channel between Apple Watch Extension/App and iOS App it would be meaningful_ . As of now there is no official documented approach, but might be of use in the near future. – GoodSp33d Nov 26 '14 at 08:26
  • Thanks, I've changed the title per your suggestion – cujo30227 Nov 26 '14 at 09:12

5 Answers5

9

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

Community
  • 1
  • 1
brian.clear
  • 5,277
  • 2
  • 41
  • 62
3

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.

3

With watchOS2 now Apple supports Watch Connectivity Framework to pass information from watch extension to app and vice versa.

Taken from Apple's docs

Communicating with Your Companion iOS App

The Watch Connectivity framework lets you create a bidirectional communications channel between your WatchKit extension and your companion iOS app. Use this channel to coordinate activities between the two processes. For example, you might use this framework to push updated information from your iOS app to your WatchKit extension. The framework provides options for transferring data in the background or while both apps are active and replaces the existing openParentApplication:reply: method of the WKInterfaceController class.

For more information the classes of the Watch Connectivity framework, see Watch Connectivity Framework Reference.

Taken from Apple's Developers Library

Emel
  • 209
  • 2
  • 8
2

You can see this library https://github.com/mutualmobile/MMWormhole

It do Message passing between iOS apps and extensions.

Mohamed Ghonemi
  • 1,072
  • 1
  • 10
  • 12
1

looks like the links with brain.clear are not pointing to the right destination for ShinobiChart example

https://github.com/ShinobiControls/ChartWatch

nakeer
  • 641
  • 1
  • 9
  • 17