2

I have an iOS 8.0 application that produces some local notifications which are shown in the global Notifications pull down (The Notifications view).

enter image description here

Perfect! Now I would like to:

  1. get all listed notifications for my app.
  2. delete a specific notification based on the userInfo I have provided when producing the local notification.

I have been looking around https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Chapters/WhatAreRemoteNotif.html#//apple_ref/doc/uid/TP40008194-CH102-SW1

And exploring the properties and methods for UIApplication:

UIApplication.sharedApplication().scheduledLocalNotifications.count

~ but that one is empty which makes sense because the notifications in the list have been fired and are no longer scheduled... so:

Which api(s) can I use for that ?

Update 1

Most recent explanation for scheduledLocalNotifications beining empty iOS 8 [UIApplication sharedApplication].scheduledLocalNotifications empty

Which lead me to a rather awkward solution storing notification in NSUserdefault by key and then later get it by key and canceling the usual way:

UIApplication.sharedApplication(<notification get from userdefaults by key>). 

BUT I really liked to get hold of a more clean iOS solution.

Community
  • 1
  • 1
pellekrogholt
  • 1,895
  • 2
  • 16
  • 18

2 Answers2

0

Try this. Fill in the predicate for your userinfo.

var app = UIApplication.sharedApplication()
for localNotification in app.scheduledLocalNotifications {
   if let notification = localNotification as? UILocalNotification {
       if whatever about your userInfo {
         app.cancelLocalNotification(notification)
    }
}
Gene De Lisa
  • 3,628
  • 1
  • 21
  • 36
  • ~ you are right about the way to delete a notification - but that assumes `app.scheduledLocalNotifications` holds some `UILocalNotifications`. My problem is that `app.scheduledLocalNotifications` is empty !? even if there are listed notifications in the pull down notifications list. – pellekrogholt Jun 05 '15 at 12:08
0

Not at all. There is no api to get that. sorry

-- you can see notifications that are pending (not yet delivered to the user) only

Daij-Djan
  • 49,552
  • 17
  • 113
  • 135
  • ok then I'm just stucked with the following use case - my app has: 4 fired local notifications in the `notifications view`; app badge count is 4. Ok perfect I clear all the notifications in the `notifications view`: 0 fired local notifications in the `notifications view`; app badge count is 4. Any hint/suggestions for solving this? (I know the api can set badge count to 0 but now I'm lost related to when that can be fired) – pellekrogholt Dec 06 '15 at 20:19
  • in applicationDidFinishLaunching OR you can use background app refresh – Daij-Djan Dec 06 '15 at 22:44