requestRecordPermission(completionHandler:)
Determines whether the app has permission to record audio.
Declaration
class func requestRecordPermission(completionHandler response: @escaping @Sendable (Bool) -> Void)class func requestRecordPermission() async -> BoolParameters
- response:
A Boolean value that indicates whether the user grants the app permission to record audio.
Discussion
Recording audio requires explicit permission from the user. The first time your app attempts to record audio input, the system automatically prompts the user for permission. You can also explicitly ask for permission by calling this method. This method returns immediately, but the system waits for user input if the user hasn’t previously granted or denied recording permission.
// Request permission to record.
if await AVAudioApplication.requestRecordPermission() {
// The user grants access. Present recording interface.
} else {
// The user denies access. Present a message that indicates
// that they can change their permission settings in the
// Privacy & Security section of the Settings app.
}Unless a user grants your app permission to record audio, it captures only silence (zeroed out audio samples).
After a user responds to a recording permission prompt from your app, the system remembers their choice and won’t prompt them again. If a user denies the app recording permission, they can grant it access in the Privacy & Security section of the Settings app.