[英]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:我考虑了两种可能的解决方案,但我不知道该怎么做:
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.
所以不会有通知显示。
Have you tried removeAllPendingNotificationRequests()
?您是否尝试过
removeAllPendingNotificationRequests()
?
See: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649509-removeallpendingnotificationrequ请参阅: https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649509-removeallpendingnotificationrequ
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.