简体   繁体   中英

How can I play an iOS system sound and cancel the callback

I have an app where I play a system sound to indicate to the user that they can begin recording. I currently use the code below.

    AudioServicesPlaySystemSoundWithCompletion(1117) {

        DispatchQueue.main.async {

            self.setupRecordingViews()

        }
        // beging recording 
    }

However the user could cancel wanting to record something once this function has begun and I need to a way to be able to cancel it in order to stop my UI changing to begin recording.

Any ideas how I could do this using a system sound? is there a way I can add an observer or delegate?

I'm not sure if I completely understand the issue, but just before you call setupRecordingViews() could you check a self.didCancel flag?

In your handler for whatever cancel button you have you would just set that:

self.didCancel = true

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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