gpt4 book ai didi

ios - 当重复设置为 yes 时,UNUserNotification 不会从挂起的通知中删除 - Swift

转载 作者:行者123 更新时间:2023-11-30 10:52:34 25 4
gpt4 key购买 nike

我一直在构建余数应用程序,在特定时间设置余数,无论是否有重复模式。

我一直在努力解决一个问题。任何帮助都有助于解决问题。

这是我面临的场景

当在没有重复模式的情况下创建剩余部分并且我正在删除剩余部分时,挂起的通知将被删除,但是当其设置为重复模式时,挂起的通知不会被删除。

这是我用于删除通知的代码。

UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
let allNotifIds = requests.map({ $0.identifier })
let pendingTaskNotifIds = taskNotificationIds.filter({ allNotifIds.contains($0) })
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: pendingTaskNotifIds)
}

添加通知的代码

  let content = UNMutableNotificationContent()

//set badge content here (get list from db and update it.)

content.badge = NSNumber(value: getBadgeCount())

content.title="sometitle";

content.body = "body data"

content.sound = UNNotificationSound.default

let twoWeeksTrigger = UNTimeIntervalNotificationTrigger(timeInterval: TimeInterval.everyTwoWeeks, repeats: true)

let id = UUID().uuidString
let request = UNNotificationRequest(identifier: id, content: content, trigger: trigger)

UNUserNotificationCenter.current().add(request)

这是我的日志,我已经创建了 2 个剩余任务(1 个是非重复任务,另一个是重复任务)

[<UNNotificationRequest: 0x600003dd5440; identifier: 06B35F80-9769-492A-8BFF-3108A11B1542, content: <UNNotificationContent: 0x600000786700; title: , subtitle: (null), body: Without repeat notification, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: com.example, launchImageName: , threadIdentifier: , attachments: (

), badge: 1, sound: <UNNotificationSound: 0x60000163b180>,, trigger: <UNCalendarNotificationTrigger: 0x6000033d7f40; dateComponents: <NSDateComponents: 0x6000005a0f20>

Calendar Year: 2019

Month: 1

Day: 22

Hour: 13

Minute: 53

Weekday: 3, repeats: NO>>,

<UNNotificationRequest: 0x600003dd3ae0; identifier: D33A49EC-DD3C-4090-AD86-9F16ED4EA6CC, content: <UNNotificationContent: 0x6000007852c0; title: , subtitle: (null), body: Repeat notification, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: com.example, launchImageName: , threadIdentifier: , attachments: (

), badge: 1, sound: <UNNotificationSound: 0x600001639800>,, trigger: <UNCalendarNotificationTrigger: 0x6000033d5740; dateComponents: <NSDateComponents: 0x6000005a1ef0>

Month: 1

Day: 22

Hour: 13

Minute: 54, repeats: YES>>]

删除两个任务后,重复任务通知会被触发,并且我的通知对象在日志中打印有重复任务对象, 只有非重复任务会被删除。这是供引用的日志。

[<UNNotificationRequest: 0x600003d2b300; identifier: D33A49EC-DD3C-4090-AD86-9F16ED4EA6CC, content: <UNNotificationContent: 0x60000079ca80; title: , subtitle: (null), body: Repeat notification, summaryArgument: , summaryArgumentCount: 0, categoryIdentifier: com.lawrence.revival.category, launchImageName: , threadIdentifier: , attachments: (

), badge: 1, sound: <UNNotificationSound: 0x60000163fde0>,, trigger: <UNCalendarNotificationTrigger: 0x6000033f9a40; dateComponents: <NSDateComponents: 0x6000005be470>

Month: 1

Day: 22

Hour: 13

Minute: 54, repeats: YES>>]

最佳答案

根据我的想法,您的标识符不同。

首先,检查您的标识符是否相同

引用此链接

https://stackoverflow.com/a/40563595/2254673

关于ios - 当重复设置为 yes 时,UNUserNotification 不会从挂起的通知中删除 - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54304261/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com