universal-tools / UTNotificationsFeedback

7 stars 0 forks source link

Issue with device permission #88

Open finalspace opened 5 years ago

finalspace commented 5 years ago

I have this use case (iOS): 1) start app
2) trigger local notification permission prompt in app, and choose "deny" 3) NotificationManager.DeviceNotificationsAllowed() returns TRUE (expecting FALSE) 4) close app, check system settings, notification is disabled 5) restart app, NotificationManager.DeviceNotificationsAllowed() returns TRUE (expecting FALSE)

6) turn off notifications by calling UTNotifications.Manager.SetNotificationsEnabled(false); UTNotifications.Manager.SetPushNotificationsEnabled(false); this time NotificationManager.DeviceNotificationsAllowed() returns false correctly

more info: with notification enabled in app. close app, turn off notification in system settings. restart app, NotificationManager.DeviceNotificationsAllowed() returns FALSE as expected

finalspace commented 5 years ago

there's no callback from permission prompt, so I use NotificationManager.DeviceNotificationsAllowed() inside Update() to retrieve the status.

yuriy-universal-ivanov commented 5 years ago

Hi @finalspace ,

May I clarify a few things regarding that issue?

  1. There is no NotificationManager.DeviceNotificationsAllowed() in UTNotifications. Are you speaking about UTNotifications.Manager.Instance.NotificationsAllowed() or in fact it's something completely else I've no idea about?
  2. Are you sure it's NotificationsAllowed and not NotificationsEnabled?
  3. What are the versions of UTNotifications, Xcode and iOS?

Best regards, Yuriy, Universal Tools team.

finalspace commented 5 years ago

Hi @yuriy-universal-ivanov thanks for the response. I pasted the method of the wrapper. the wrapper does nothing but simply call UTNotifications.Manager.Instance.NotificationsAllowed(). Sorry for that.

I trigger the permission prompt by executing the following methods: UTNotifications.Manager.Instance.Initialize(false); UTNotifications.Manager.Instance.SetNotificationsEnabled(true); UTNotifications.Manager.Instance.SetPushNotificationsEnabled(true);

when user denies the permission, UTNotifications.Manager.Instance.NotificationsAllowed() gives me TRUE in MonoBehaviour.Update()

the workaround that I figured out is that I need to reset the status of the manager by calling UTNotifications.Manager.Instance.SetNotificationsEnabled(false); UTNotifications.Manager.Instance.SetPushNotificationsEnabled(false); in the next frame. after this, UTNotifications.Manager.Instance.NotificationsAllowed() gives me the correct value.

in case user allows the permission, I tried re-enable notification by doing if (UTNotifications.Manager.Instance.NotificationsAllowed()) { UTNotifications.Manager.Instance.SetNotificationsEnabled(true); UTNotifications.Manager.Instance.SetPushNotificationsEnabled(true); } in the next frame

so basically the bug I found is that I need to call UTNotifications.Manager.Instance.SetNotificationsEnabled(false); UTNotifications.Manager.Instance.SetPushNotificationsEnabled(false); after the promt to have UTNotifications.Manager.Instance.NotificationsAllowed() work correctly.

Is it because the way I use that cause this problem? I'm using Unity 2017.4.10f1 UTNotification 1.7.3 Xcode 9.2 (for local build)

yuriy-universal-ivanov commented 5 years ago

Hi @finalspace ,

I tried and couldn't reproduce your issue. It works absolutely as expected for me:

  1. NotificationsAllowed returns false before Initialize is called or before the permission dialog is closed
  2. It returns true if you chose to allow in the dialog
  3. It returns false if you chose to not allow in the dialog.

The same thing: the check is in Update(), having UTNotifications.Manager.Instance.SetNotificationsEnabled(true); UTNotifications.Manager.Instance.SetPushNotificationsEnabled(true); after the initialization doesn't matter (I tried adding it and not adding it, it doesn't change the behaviour anyhow).

Could you maybe post here your complete script which reproduces the issue? Please also tell me the version of iOS on the device you're running it.

Best regards, Yuriy, Universal Tools team.