首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >当重复设置为yes - Swift时,UNUserNotification不会从挂起的通知中删除

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

Stack Overflow用户
提问于 2019-01-22 08:40:51
回答 1查看 557关注 0票数 0

我已经建立了余数应用程序设置在一个特定的时间与或不重复模式。

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

下面是我所面临的情况

当创建余数时没有重复模式,而我正在删除剩余部分,挂起通知将被删除,但当其设置为重复模式时,挂起通知不会被删除。

下面是删除通知的代码。

代码语言:javascript
复制
UNUserNotificationCenter.current().getPendingNotificationRequests { requests in
            let allNotifIds = requests.map({ $0.identifier })
            let pendingTaskNotifIds = taskNotificationIds.filter({ allNotifIds.contains($0) })
            UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: pendingTaskNotifIds)
        }

添加通知的代码

代码语言:javascript
复制
  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)

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

代码语言:javascript
复制
[<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>>]

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

代码语言:javascript
复制
[<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>>]
EN

回答 1

Stack Overflow用户

发布于 2019-01-22 11:00:10

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

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

引用此链接

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54304261

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档