icerockdev / moko-permissions

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

Invalid permission for REMOTE_NOTIFICATION on iOS #61

Open ncltg opened 2 years ago

ncltg commented 2 years ago

The issue

When calling permissionsController.getPermissionState() with Permission.REMOTE_NOTIFICATION, I always get the same value : DeniedAlways.

I'm testing it by deleting completely my app for my test phone. At the time the call is made no authorization has been requested by the user yet. In fact, just to be sure I also checked into the settings of the app that the Notification setting row does not appear.

What I tested

I first tested to prompt the notification status by logging it in my iOS app that way :

    let currentCenter = UNUserNotificationCenter.current()
    currentCenter.getNotificationSettings { value in
      print(value.authorizationStatus)
    }

Which gives me this output :

<UNNotificationSettings: 0x28002ac70; authorizationStatus: NotDetermined, notificationCenterSetting: NotSupported, soundSetting: NotSupported, badgeSetting: NotSupported, lockScreenSetting: NotSupported, carPlaySetting: NotSupported, announcementSetting: NotSupported, criticalAlertSetting: NotSupported, timeSensitiveSetting: NotSupported, alertSetting: NotSupported, scheduledDeliverySetting: NotSupported, directMessagesSetting: NotSupported, alertStyle: None, groupingSetting: Default providesAppNotificationSettings: No>

Everything is fine here so I moved on with trying to get the value myself from my KMM/iosMain code :

    fun getPermissionState() {
        val currentCenter = UNUserNotificationCenter.currentNotificationCenter()
        currentCenter.getNotificationSettingsWithCompletionHandler { settings: UNNotificationSettings? ->
            Log.debug(settings?.authorizationStatus.toString()) // returns 0 for UNAuthorizationStatus.notDetermined
        }
    }

I get the right result even in the kmm side, while at the same time I still get .DeniedAlways from moko.permissions

Any idea where this issue could originate from ?

petarmarijanovicfive commented 2 years ago

+1! There are multiple issues with iOS Remote notifications, which makes this library for Kotlin Mobile development useless.

@Alex009 we've just merged the Android support for Remote notifications. Can we do the same for iOS as well 😁

Alex009 commented 1 year ago

@petarmarijanovicfive you can create PR with fixes. i think now we not have case NotDetermined just because android can't tell us same state

Alex009 commented 1 year ago

i check now on 0.15.0 dev version and i see that getPermissionState return NotDetermined on iOS on clean install

image
Alex009 commented 1 year ago

DeniedAlways will be after trying to request permission and user decline this request