0

I want to avoid to display a local scheduled notification if the user has disabled notification from the app settings.

However, it doesn't seem possible.

I have think about two possible solution, but i don't know how to do it:

  • Like a remote data notification, which is not displayed into the notification center if you don't manually do it, does we have an equivalent mechanism for local notification ?
  • Another solution would be to be able to listen "app notification setting change", but i've not find any information about it.

For the moment, my best solution is too check getNotificationSettings each time the app come back in foreground. if status isn't authorized, then i call removePendingNotificationRequests. However, if user don't open the app before the scheduled event is fired, this workaround isn't sufficient.

Klaonis
  • 163
  • 2
  • 12

2 Answers2

1

You can not listen status change. Only way is when user opens the app check getNotificationSettings

I want to avoid to display a local scheduled notification if the user has disabled notification authorisation from the app settings.

If user has disabled notification permission through the Settings. So there will be no notification to show.

Clown
  • 163
  • 1
  • 12
  • It's wrong. Even if user has disabled notification from App settings, local notification can always be fired. See Apple note about this right here : https://developer.apple.com/documentation/usernotifications/asking_permission_to_use_notifications. It says "Always check your app’s authorization status before scheduling local notifications. ". But they don't explain how to handle an already scheduled notification, if user disables notification before this notification is fired. – Klaonis Apr 30 '20 at 12:44
  • Documentation warns developers about "always check before register new notif. because it may not work, or crash if not handled well". Disabling permission through Settings won't show any new notification. You can test in simulator, local notifications are available, you can make with 1 min interval. 10 notif then change permission in settings to see. – Clown Apr 30 '20 at 13:10
  • you can check this answer there is matrix explains use-cases. https://stackoverflow.com/questions/30644343/is-silent-remote-notifications-possible-if-user-has-disabled-push-for-the-app – Clown Apr 30 '20 at 13:12
0

Have you tried removeAllPendingNotificationRequests()?

See: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649509-removeallpendingnotificationrequ

acodeguy
  • 115
  • 1
  • 7
  • My problem is not "How" to remove pendingNotification, but "when" i want to do it. I want to be 100% sure that my scheduled local notifications are not shown WHEN user has disable notification from app settings. – Klaonis Apr 30 '20 at 12:41