简体   繁体   English

取消已安排的本地通知

[英]Cancel a local notification which has been scheduled

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.目前,我最好的解决方案是每次应用程序回到前台时检查getNotificationSettings if status isn't authorized , then i call removePendingNotificationRequests .如果状态未被authorized ,那么我调用removePendingNotificationRequests However, if user don't open the app before the scheduled event is fired, this workaround isn't sufficient.但是,如果用户在触发预定事件之前未打开应用程序,则此解决方法是不够的。

You can not listen status change.你不能听状态变化。 Only way is when user opens the app check getNotificationSettings唯一的方法是当用户打开应用程序时检查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.所以不会有通知显示。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM