如何在Apple Watch Extension / App和iOS App之间建立通信渠道 [英] How to establish a communication channel between Apple Watch Extension/App and iOS App

查看:436
本文介绍了如何在Apple Watch Extension / App和iOS App之间建立通信渠道的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索WatchKit SDK。

I'm exploring the WatchKit SDK.

当我有一个WatchKit应用程序时,是否可以从iPhone应用程序设置值(例如文本,设置) WatchKit应用程序?我可以通过iPhone应用程序调用WatchKit应用程序扩展中的函数吗?

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!

推荐答案

您可以使用App Group和sharedDefaults在手机上的WatchApp /分机和应用程序之间共享数据。
见例如:
WatchKit SDK不NSUserDefaults的从数据检索

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

研究iOS8扩展/应用组/ sharedDefaults和watchkit扩展将更有意义。

Study up on iOS8 Extension/App Groups/sharedDefaults and watchkit extension will make more sense.

此示例从Shinobi图表中获取UIImage,将其保存为默认值为image。
然后,分机通过默认值获取图像并在手表上显示

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

但是这使用了蓝牙,我认为Watch OS也使用蓝牙与手机通信,所以不确定它们是否都被允许。

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.

我们还没有可以测试的设备所以/ swatches app只是在同一台Mac上与iphone模拟器通话时观看模拟器。

We have no devices to test on yet so the /swatches app is just watch simuator talking to iphone simulator on same mac.

如果您曾经进行过低级别的AV编程,您就会知道应用程序可能在模拟器上运行但在设备上失败,因为模拟器可能会欺骗使用Mac OSX媒体层。对于蓝牙可能是相同的。

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.

其他样本

https://github.com/search?q=WKInterfaceController&type=Code

这篇关于如何在Apple Watch Extension / App和iOS App之间建立通信渠道的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆