icerockdev / moko-permissions

Runtime permissions controls for mobile (android & ios) Kotlin Multiplatform development
https://moko.icerock.dev/
Apache License 2.0
366 stars 36 forks source link

Multiple permission #122

Open fjr619 opened 3 months ago

fjr619 commented 3 months ago

Hi may i get example how to handle multiple permissions with moko? do i need create multiple controller for that too?

Alex009 commented 3 months ago

just call providePermission multiple times

class ViewModel(val permissionsController: PermissionsController): ViewModel() {
    fun onPhotoPressed() {
        viewModelScope.launch {
            try {
                permissionsController.providePermission(Permission.GALLERY)
                permissionsController.providePermission(Permission.CAMERA)
                // Permission has been granted successfully.
            } catch(deniedAlways: DeniedAlwaysException) {
                // Permission is always denied.
            } catch(denied: DeniedException) {
                // Permission was denied.
            }
        }
    }
}
andiosdev commented 2 months ago

@Alex009 Is the same applies if its for location permission?

Alex009 commented 2 months ago

Yes