how to pass some message or string from iphone device to paired apple watch

南楼画角 提交于 2020-01-05 09:24:11

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/27853446/how-to-pass-some-message-or-string-from-iphone-device-to-paired-apple-watch

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!