1

I have an iPhone app and added a WatchExtension. Now I managed to send a string to the Watch using the MMWormhole. In order to use the string I must call update() inside the WKInterfaceController from a method inside my UIViewController, so the iPhone application.
Is that possible?

I tried to do something like InterfaceController.update() but Xcode complained that it does not know the variable InterfaceController.

Thanks in advance :)

LinusGeffarth
  • 27,197
  • 29
  • 120
  • 174
  • so for the flow...is this correct? The watch sends a message to the phone, the phone replies back with a string, and you want to call a method on a `WKInterfaceController`? So is the whole process initiated by some action on the watch? – prawn Apr 24 '15 at 18:45
  • Actually no, I send a message from the phone when the screen is tapped. The watch does not send anything. Sorry if that was unclear. – LinusGeffarth Apr 24 '15 at 18:50
  • You may use Darwin notifications. See here: [Notify WatchKit app of an update without the watch app requesting it][1] [1]: http://stackoverflow.com/questions/28809226/notify-watchkit-app-of-an-update-without-the-watch-app-requesting-it – John May 03 '15 at 15:04

1 Answers1

2

The iPhone App and Watch Extension are TWO seperate process, although they are stored in ONE bundle, so you can not call the method of other process in runtime.

In WatchKit:

  • If you want to share code, use Framework.
  • If you want to share data, use App Group.
  • If you want to use notification, use Inter-Process Communication(In iOS, It's Darwin Notification, and MMWormhole use this feature).

I think you want to let the Watch update its interface when iPhone app do something, you can do like this:

  1. send a message to Watch Extension.
  2. Watch Extension receive that message.
  3. In the message handler, update interface.

In my option, the iPhone App and Watch Extension can be seen as a kind of C/S architecture, iPhone App is Server and Watch Extension is Client, maybe this metaphor is easier to understand.

Joe Shang
  • 139
  • 1
  • 5