Permission Handling in Compose Multiplatform - KMP for Beginners

Поделиться
HTML-код
  • Опубликовано: 28 ноя 2024

Комментарии • 27

  • @yashinshekh802
    @yashinshekh802 4 месяца назад +20

    you are the only reason i am learning kotlin instead of flutter

    • @Chirag-Redij38
      @Chirag-Redij38 4 месяца назад +1

      No kidding. My android journey started because of Philipp. My first project was inspired (basically copied) from his Running tracker app.

  • @roshkaalex
    @roshkaalex 4 месяца назад +5

    Thank you! Will you create video with firebase crashlytics and may be firebase push notification? Camera functionality is also interesting :)

  • @timdavidfriedrich
    @timdavidfriedrich 4 месяца назад +1

    Thank you! A topic which I'd love to see as well, would be KMP with a multi-module app structure :)
    Would be super helpful, seeing this explained by you

  • @santyas
    @santyas 4 месяца назад +1

    Great video Philipppp! Should be great to find how to solve to manage multilang iOS param string from the kmp project instead xcode hardcoding :)

  • @tch.777
    @tch.777 4 месяца назад

    Amazing like always, ty ❤🙏

  • @_hudeifa23
    @_hudeifa23 4 месяца назад +1

    do the notification in CMP please

  • @lokiksoni3519
    @lokiksoni3519 4 месяца назад +1

    This is my way of handling the permission with the same library.
    Inside the composable screen where you want to ask permission
    val permissionHandler = rememberPermissionHandler()
    when(permissionHandler.permissionState) {
    PermissionState.Granted -> {}
    PermissionState.DeniedAlways -> {
    PermissionDeniedDialog(
    onDismissRequest = {
    },
    onConfirmation = {
    permissionHandler.openAppSetting()
    }
    )
    }
    else -> {
    permissionHandler.requestPermission()
    }
    }
    @Composable
    fun rememberPermissionHandler(): PermissionHandler {
    val scope = rememberCoroutineScope()
    val factory = rememberPermissionsControllerFactory()
    val controller = remember(factory) {
    factory.createPermissionsController()
    }
    BindEffect(controller)
    return remember(controller) {
    PermissionHandler(
    controller,
    scope
    )
    }
    }
    @Stable
    class PermissionHandler(
    private val _controller: PermissionsController,
    private val _scope: CoroutineScope,
    ) {
    var permissionState by mutableStateOf(PermissionState.NotDetermined)
    init {
    _scope.launch {
    permissionState = _controller.getPermissionState(Permission.LOCATION)
    }
    }
    fun openAppSetting() {
    _scope.launch {
    _controller.openAppSettings()
    }
    }
    fun requestPermission() {
    _scope.launch {
    try {
    _controller.providePermission(Permission.LOCATION)
    permissionState = PermissionState.Granted
    } catch (e: DeniedAlwaysException) {
    permissionState = PermissionState.DeniedAlways
    } catch (e: DeniedException) {
    permissionState = PermissionState.Denied
    } catch (e: RequestCanceledException) {
    e.printStackTrace()
    }
    }
    }
    }

  • @webbiagio
    @webbiagio 2 месяца назад

    In this example we create a controller object in a composable and then pass it to the viewmodel, whose lifecycle is longer living that the activity one. In a pure Android application that is a bad practice, since a configuration change can lead to problems. Am I missing something? Maybe in KMP the rules in this scenario are different than in pure Android?

  • @UniverseZ333
    @UniverseZ333 4 месяца назад

    Greetings from Brazil. Do you really think KMP is the future? I am speciallizing on it, very disciplined, programing everyday, but struggling to find remote jobs as I live in a small city. Should I keep trying?

  • @GoopleDev-o6u
    @GoopleDev-o6u 4 месяца назад +4

    Can this be implemented using DI koin?

    • @Chirag-Redij38
      @Chirag-Redij38 4 месяца назад

      Yeah main question, since the controller was bounded to the screen. Or we can do is using a Launched effect an providing an object of controller to the ViewModel. Hoping this would work.

    • @PhilippLackner
      @PhilippLackner  4 месяца назад

      What would be the benefit of doing that?

    • @imostafa70
      @imostafa70 4 месяца назад +1

      @@PhilippLackner Consistency in project. Because in real projects we mostly use DI frameworks, and what if we need to inject some repositories or use cases as well to our ViewModel class?

    • @Axelfromthehudjelud
      @Axelfromthehudjelud 3 дня назад

      ​@PhilippLackner i already create my ViewModel in Koin because of other dependencies, that would be the benefit

  • @Chirag-Redij38
    @Chirag-Redij38 4 месяца назад

    Is it necessary for app to be relaunched on IOS for it to get permission acceptance changes?

  • @mollyolly3173
    @mollyolly3173 4 месяца назад

    Hi dude, I wanted to know which operating system is the best to use linux or windows? and after KMP, you write app for ios using swift or objective-c or you only Android dev?

    • @mollyolly3173
      @mollyolly3173 4 месяца назад

      And yes, thank you for the video

  • @UsmonWasTaken
    @UsmonWasTaken 4 месяца назад

    Can you do front lever?

  • @lokiksoni3519
    @lokiksoni3519 4 месяца назад

    The button don't get hidden when we back from setting to the app we have to relaunch the app to update state.

  • @mahaks-u8x
    @mahaks-u8x 3 месяца назад

    How can we take multiple permission on single click: like for Location and Storage?

  • @swapniljadhav1296
    @swapniljadhav1296 4 месяца назад

    Dispointed when got to know No ConstraintLayout in CMP.

    • @PhilippLackner
      @PhilippLackner  4 месяца назад +1

      @@swapniljadhav1296 I don't think I ever used that in compose in my life 😅

    • @swapniljadhav1296
      @swapniljadhav1296 4 месяца назад

      @@PhilippLackner ConstraintLayout reduces layers and gives more control.

  • @abdullahkardas8887
    @abdullahkardas8887 4 месяца назад

    first

  • @abdelrahmankhaled7575
    @abdelrahmankhaled7575 4 месяца назад +1

    Thank You , I Think it`s Time To Local Database And Show Notifications so all the basics is covered 🫶