在某些情况下,我需要检查用户是否应该根据其位置接收推送通知。我知道UNNotificationServiceExtension
可以帮助我们拦截通知并有助于构建推送内容。但是,对于此类或其他任何地方,我们是否有可能通过检查用户的位置来不显示推送通知?
这并不意味着我每次都想这样做。但只有当我的条件没有得到满足时。在通知内容中,我正在获取用户的上次跟踪位置,我将使用该位置与用户的当前位置进行比较。
我经历了这个,但没有得到令人信服的答案。
注意:我不是在寻找静默推送通知解决方案。
使用 UNUserNotification Center,您可以按 id 取消单个通知。
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [SomeID])
您必须实现 UNUserNotificationCenter Delegate 并实现userNotificationCenter(_:willPresent)
像这样:
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let identifier = notification.request.identifier
let content = notification.request.content
//your logic here
}