取消已安排的本地通知

Cancel a local notification which has been scheduled

如果用户已从应用设置中禁用通知,我想避免显示本地预定通知。

然而,这似乎不可能。

我想过两种可能的解决方案,但我不知道该怎么做:

目前,我最好的解决方案是每次应用返回前台时都检查 getNotificationSettings。如果状态不是 authorized,那么我会调用 removePendingNotificationRequests。 但是,如果用户在触发预定事件之前没有打开应用程序,则此解决方法是不够的。

你试过了吗removeAllPendingNotificationRequests()

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

您无法收听状态变化。唯一的方法是当用户打开应用程序时检查 getNotificationSettings

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

如果用户通过设置禁用了通知权限。所以不会有通知显示。