0

I have been building the remainder app setting remainder at a particular time with or without repeat mode.

I have been struggling to solve one issue. any help would be helpful to get it resolved.

Here is the scenario that I am facing

When the remainder is created without repeat mode and I am deleting the remainder the pending notification gets removed, but when its set as repeat mode the pending notification is not getting removed.

here is my code to get the notification removed.

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

code to add notification

  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)

Here is my log, I have created 2 remainders created (1 is a non-repeating task and another one is repeating task)

[<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>>]

After deleting both the tasks notification gets fired for repeating the task and my notification object has repeating task object printed in log, only the non-repeating tasks get removed. Here is the log for reference.

[<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>>]
Aravindh Kumar
  • 1,213
  • 11
  • 22

1 Answers1

0

As per my thought, your identifier is different.

First, a check is your identifier is same or not

Reference this link

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

viki
  • 41
  • 1
  • 5
  • I have matched the id and then I am removing the notification with id reference id `D33A49EC-DD3C-4090-AD86-9F16ED4EA6CC` and it also prints the same in the log. – Aravindh Kumar Jan 22 '19 at 12:15
  • can you please share code, How you are adding repeat notification. just add different categoryIdentifier for a repeat. – viki Jan 22 '19 at 12:20
  • First UUID().uuidString will give different string every time. so pls change identifier and add some meaning full identifier – viki Jan 22 '19 at 13:21
  • I need a unique id(UUID) for a different task. when deleting the task from UI I will get the task id which is used as the notification id, if the match occurs then delete it else leave the notification. – Aravindh Kumar Jan 22 '19 at 13:28