1

I would like to know how a particular message or string can be passed from my iPhone device to the paired iWatch. I would really like to know how this is handled from development point of view. Is there any particular WKInterfaceController method or API which passes the info from iPhone to iWatch?

I have read on developer forum that openParentApplication:reply: notifies the iPhone application from iWatch and application:handleWatchKitExtensionRequest:reply handles that particular notification request on iPhone. But I want the reverse.

Lets say, I have an iPhone application storyboard scene with a UITextField and UIButton. User enters "Hello !" on text field and clicks on button. Now I have a watch kit extension within the same project with an iwatch storyboard. This storyboard scene has an "WKInterfaceLabel". I would like to have my iPhone controller interact with WKInterfaceController so that the message entered on iphone stroyboard ("Hello !" in this case) can be passed to the iWatch controller and displayed on the iWatch.

Hugo Alonso
  • 6,684
  • 2
  • 34
  • 65
anshul
  • 846
  • 1
  • 14
  • 32

2 Answers2

2

In order to communicate from iPhone to your watch, you need to use app groups, and darwin notifications. You can use MMWormhole (available here) to do this.

Axadiw
  • 651
  • 8
  • 19
  • Wormhole seems to give the functionality asked for. What i don't understand is how it works. If apple don't provide anyway to call to the watch kit. How is Wormhole working? I'm guessing it must poll some kind of storage for the message as it relies on the app group. Surely this is a really inefficient way of doing this. – Lightbulb1 Apr 01 '15 at 10:55
  • it's using darwin notification center, that allows to perform IPC between active processes – Axadiw Apr 01 '15 at 15:03
  • I've done some more research on it now and understand that wormwhole is a wrapper for the darwin notifications. Theres no polling involved. I read on someones blog post about this, that he had concerns that apple may not allow darwin notification to do this anymore. [This](http://www.atomicbird.com/blog/sharing-with-app-extensions) is the post. The bit mention darwin notifications is at the bottom. Any thoughts on how safe darwin notification are for this purpose? – Lightbulb1 Apr 02 '15 at 08:32
  • In first post from this thread: https://devforums.apple.com/thread/256667?start=0&tstart=0 They're mentioning Darin notification center, so I guess that it's rather safe. – Axadiw Apr 02 '15 at 10:25
1

MMWormhole will do the required work. It uses darwin notification center to communicate between app and its extensions.

Simply install it using CocoaPods, or add MMWormhole.h and MMWormhole.m into your project.

Hope this helped.

sudhanshu-shishodia
  • 1,100
  • 1
  • 11
  • 25