取消已安排的本地通知
Cancel a local notification which has been scheduled
如果用户已从应用设置中禁用通知,我想避免显示本地预定通知。
然而,这似乎不可能。
我想过两种可能的解决方案,但我不知道该怎么做:
- 像远程数据通知,如果不手动是不会显示到通知中心的,我们本地通知有没有等价的机制?
- 另一种解决方案是能够收听 "app notification setting change",但我没有找到任何相关信息。
目前,我最好的解决方案是每次应用返回前台时都检查 getNotificationSettings
。如果状态不是 authorized
,那么我会调用 removePendingNotificationRequests
。
但是,如果用户在触发预定事件之前没有打开应用程序,则此解决方法是不够的。
你试过了吗removeAllPendingNotificationRequests()
?
您无法收听状态变化。唯一的方法是当用户打开应用程序时检查 getNotificationSettings
I want to avoid to display a local scheduled notification if the user
has disabled notification authorisation from the app settings.
如果用户通过设置禁用了通知权限。所以不会有通知显示。
如果用户已从应用设置中禁用通知,我想避免显示本地预定通知。
然而,这似乎不可能。
我想过两种可能的解决方案,但我不知道该怎么做:
- 像远程数据通知,如果不手动是不会显示到通知中心的,我们本地通知有没有等价的机制?
- 另一种解决方案是能够收听 "app notification setting change",但我没有找到任何相关信息。
目前,我最好的解决方案是每次应用返回前台时都检查 getNotificationSettings
。如果状态不是 authorized
,那么我会调用 removePendingNotificationRequests
。
但是,如果用户在触发预定事件之前没有打开应用程序,则此解决方法是不够的。
你试过了吗removeAllPendingNotificationRequests()
?
您无法收听状态变化。唯一的方法是当用户打开应用程序时检查 getNotificationSettings
I want to avoid to display a local scheduled notification if the user has disabled notification authorisation from the app settings.
如果用户通过设置禁用了通知权限。所以不会有通知显示。