在多个iOS设备上同时触发事件 [英] triggering an event simultaneously on multiple iOS devices

查看:54
本文介绍了在多个iOS设备上同时触发事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在同一时间(以毫秒为单位)在多个iOS设备上触发一个事件(例如,播放音乐)

I would like to trigger an event (e.g. play music) on multiple iOS devices at the exact same time (by means of milliseconds)

我的方法是保持套接字连接并向iOS设备发送时间戳(比当前时间晚10秒),然后在该时间戳上触发iOS设备上的事件.

My approach is to keep a socket connection and send a timestamp to iOS devices (10 seconds later from current time) and trigger the event on iOS devices at that timestamp.

问题是iOS设备可能相差1或2秒,这将导致不同步.甚至时间戳都指示每个设备(AFAIK)的时间相同,而不是毫秒级.

Problem is iOS devices might differ 1 or 2 seconds and that would cause a desynchronize. And even timestamps are pointing out the same time on each devices (AFAIK) they are not on millisecond sensivity.

有没有办法在多个设备上同时触发事件,或者应该遵循的方法?

Is there any way to trigger an event simultaneously on multiple devices, or an approach which should be followed?

推荐答案

不要通过Internet发送数据.您不能假设连接等待时间不足以满足您的需求.请改用蓝牙.您可以使用GameKit,dns-sd或 HHServices 之类的库.

Don't send the data over the Internet. You can't assume the connection latency will be low enough for your needs. Use Bluetooth instead. You can do with with GameKit, with dns-sd, or with a library like HHServices.

选择一个将充当控制器的设备. Apple提供了使用GameKit进行操作的示例代码,但是想出自己的方法并不难.当您要触发操作时,该控制器将通过蓝牙将数据包发送到其他设备.

Pick a device that will act as the controller. Apple provide sample code to do so with GameKit, but it's not difficult to think up your own method. When you want to trigger the action, that controller will send a packet over Bluetooth to the other devices.

我怀疑您是否需要比这更低的延迟,但是如果这样做,请让控制器将数据包发送到每个已连接的设备以​​确定每个连接的延迟,然后将它们的时间戳发送给控制器,那么控制器应该能够计算将在同一时间出现的每个时间戳.

I doubt you need lower latency than that, but if you do, have the controller send packets to each connected device to ascertain the latency for each connection, have them send their timestamps to the controller, then the controller should be able to calculate a timestamp for each of them that will occur at the same time.

这篇关于在多个iOS设备上同时触发事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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