IOS: 0 timing or delayed execution of error or minimum error?

Source: Internet
Author: User

The problem is as follows:

Rhythm games require a lot of action related to the rhythm of the music, and in order to maintain the rhythm, it is necessary to have a close relationship with the beat. The interval requirement cannot exceed 0.02 seconds or less.

The Asyncafter (Deadline:) method in GCD is currently used, but the error is always greater than 0.05 seconds, and there is no guarantee that the error will pass. Is there a better way to solve the error?

var time = Date().timeIntervalSince1970let dq = DispatchQueue(label: "queue", qos: .userInitiated, attributes: [.concurrent, .initiallyInactive])            dq.async {                self.audioPlayer.play()                time = Date().timeIntervalSince1970            }            dq.asyncAfter(deadline: .now() + 0.43, execute: {                let res = Date().timeIntervalSince1970                print(" 误差: \(res - time)")                            })

The following is a multiple-run console print result (this number refers to the actual interval, which is far from 0.43 of the expected interval and is not stable):


IOS: 0 timing or delayed execution of error or minimum error? >> iOS

The answer is quite clear:
Http://www.goodpm.net/postreply/ios/1010000008928622/iOS 0 Timing or delay execution of error or minimum error. html

IOS: 0 timing or delayed execution of error or minimum error?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.