Have two different iPhones run code at the same exact time
<p>Currently, the app consists of this - setting a trigger time using <code>UIDatePicker</code> and then when this set <code>NSDate</code> comes around, play a .mov file. I recently tried running the app on 4 different iOS devices and got pretty terrible results. It appeared as if every device was just slightly out of sync resulting in the music sounding very awkward. However, I occasionally have trials between my iPhone 6S and 6S+ that are almost perfectly in sync. To run the code at a specific time I'm using the following code.</p>

<pre><code>let now = NSDate()

let timeDelta = self.appDelegate.triggerDate.timeIntervalSinceDate(now)

let timeDeltaDouble = Double(timeDelta)

print(timeDeltaDouble)

self.delay(timeDeltaDouble) {

    self.player.play()

}
</code></pre>

<p>Where delay is</p>

<pre><code>func delay(delay:Double, closure:()-&gt;()) {
        dispatch_after(
            dispatch_time(
                DISPATCH_TIME_NOW,
                Int64(delay * Double(NSEC_PER_SEC))
            ),
            dispatch_get_main_queue(), closure)
}
</code></pre>

<p>Considering that my results are not very promising, I'm assuming there is a better way of achieving this effect. Would love to learn about a better way to achieve this! And why exactly this method isn't working out.</p>

<p>EDIT: Also, I'm making sure that when the <code>UIDatePicker</code> returns a date that the date has seconds set to 0 to keep things uniform.</p>