All Downloads are FREE. Search and download functionalities are using the official Maven repository.

iosMain.io.github.kpermissions.handler.permissions.requestMicrophonePermission.kt Maven / Gradle / Ivy

The newest version!
package io.github.kpermissions.handler.permissions

import platform.AVFAudio.AVAudioSession
import platform.AVFAudio.AVAudioSessionRecordPermissionGranted
import platform.AVFAudio.AVAudioSessionRecordPermissionUndetermined

fun requestMicrophonePermission(onPermissionResult: (Boolean) -> Unit) {
    val permissionStatus = AVAudioSession.sharedInstance().recordPermission()
    when (permissionStatus) {
        AVAudioSessionRecordPermissionGranted -> {
            onPermissionResult(true)
        }

        AVAudioSessionRecordPermissionUndetermined -> {
            AVAudioSession.sharedInstance().requestRecordPermission { granted ->
                onPermissionResult(granted)
            }
        }

        else -> {
            onPermissionResult(false)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy