AVAudioRecorder doesn't record while screen is locked

前端 未结 3 2029
长情又很酷
长情又很酷 2020-12-12 00:14

I\'ve tried to overcome this for a while. I\'m trying to record sound, but the AVAudioRecorder doesn\'t record while screen is locked. It does continue to record once screen

3条回答
  •  轮回少年
    2020-12-12 00:16

    Ok, so the answer to my own question, which took me a long time to find out, is the following: The code I posted is good, but to actually work it needs to work in the background after screen was locked. For this one needs to add a UIBackgroundModes array in the app's plist file, and add 'audio' as one of its objects. This tells the system to let the app work with audio in the background.

    Here's the not-so-easy to find documentation. Unfortunately apple doesn't specify that in their documentation of the audio session categories where they claim certain categories work in the background. Anyway, hopefully this answer will be available for others who have a similar problem...

提交回复
热议问题