AVAudioRecorder doesn't record while screen is locked

前端 未结 3 2028
长情又很酷
长情又很酷 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...

    0 讨论(0)
  • 2020-12-12 00:20

    You may want to consider setting the category as AVAudioSessionCategoryRecord to the AudioSession

    0 讨论(0)
  • 2020-12-12 00:27

    How about disabling the screen lock until you are done recording?

    [UIApplication sharedApplication].idleTimerDisabled = YES;
    
    // Do recording here
    
    [UIApplication sharedApplication].idleTimerDisabled = NO;
    

    Just don't forget to re-enable the screen lock when you're done!

    0 讨论(0)
提交回复
热议问题