简体   繁体   English

通过Swift中的Multipeer Connectivity临时同步两个iOS设备

[英]Temporally synchronize two iOS devices over Multipeer Connectivity in Swift

I would like to temporally synchronize two iOS devices using Multipeer Connectivity (so it should work for both WIFI and Bluetooth) in Swift. 我想在Swift中使用Multipeer Connectivity(因此应该同时适用于WIFI和蓝牙)暂时同步两个iOS设备。

Ideally, I would need a synchronisation within 0.03 ms, but 0.3 ms would be acceptable. 理想情况下,我需要在0.03毫秒内进行同步,但是0.3毫秒是可以接受的。

So far, I am playing a sound from device 1 and record it with device 2, measuring the time from the moment when the devices are connected with each other over Multipeer Connectivity. 到目前为止,我正在播放设备1发出的声音,并用设备2录制声音,测量从设备通过Multipeer Connectivity相互连接起的时间。

Unfortunately, this does not provide the accurate temporal synchronization needed for my application. 不幸的是,这不能提供我的应用程序所需的准确时间同步。

Just send the current time from one device and then compare it on the other side when the message is received. 只需从一台设备发送当前时间,然后在收到消息时在另一侧进行比较即可。

Preparing message: 正在准备消息:

// this is the value to send    
let date = NSDate()

On the message received code: 在消息上收到代码:

let interval = NSDate.timeIntervalSinceDate(theDate)

That interval is the time passed since the initial date was created on the other device. 该间隔是自在另一台设备上创建初始日期以来经过的时间。

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

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