简体   繁体   English

IOS & WatchOS后台通讯

[英]IOS & WatchOS background communication

I have a IOS application with a companion WatchOS application.我有一个带有配套 WatchOS 应用程序的 IOS 应用程序。 I am wondering if there is a way I can communicate with the IOS application in real time while it not running as a foreground application.我想知道是否有一种方法可以在 IOS 应用程序不作为前台应用程序运行时与它进行实时通信。

The best example I can think of is how your are able to use the Spotify watch app to change songs, like songs or even change the volume of the phone while the phone is locked.我能想到的最好的例子是你如何能够使用 Spotify 手表应用程序来改变歌曲,比如歌曲,甚至在手机锁定时改变手机的音量。

How could I implement something like this for an application that could possibly send data frequently from the watch to the phone while the phone is locked.对于可能在手机锁定时频繁从手表向手机发送数据的应用程序,我该如何实现类似的功能。

Watch apps can launch their companion iOS apps by messaging them:.观看应用程序可以通过发送消息来启动其配套的 iOS 应用程序:。 https://developer.apple.com/documentation/watchconnectivity/wcsession/1615687-sendmessage https://developer.apple.com/documentation/watchconnectivity/wcsession/1615687-sendmessage

That won't work if the iOS device requires unlock because it's just booted up.如果 iOS 设备需要解锁,因为它刚刚启动,这将不起作用。

I just started WatchOS development and needed to send a message to the watch app - if it's available I use sendMessage .我刚刚开始 WatchOS 开发,需要向手表应用程序发送消息 - 如果它可用,我使用sendMessage If the watch app is backgrounded, I use transferUserInfo .如果手表应用程序是后台的,我使用transferUserInfo Link to code snippets . 链接到代码片段 I check isReachable and isPaired (on the phone, isPaired does not exist in WatchOS).我检查了isReachableisPaired (在手机上,isPaired 在 WatchOS 中不存在)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM