iOS clear push notifications
Asked Answered
S

2

9

I notice that for apps like Google Hangout, Facebook etc. when I get a push notification for any event (people writing on my wall, etc.), if I view the event on my desktop, it will clear the push notification (which I have not cleared myself or opened the app for) on my iPhone.

How can I implement the same?

Right now i'm using this app for implementing my push's.

I customized the above, but the implementation is similar. Do I need to send any special data to the phone to clear all notifications from my app?

Studding answered 14/1, 2014 at 21:17 Comment(0)
W
2

I did same in my application that read notifications don't remain in Application. Buts its not how you think it is.

i Saved Remote Notification in method didReceiveRemoteNotification: in DataBase (Coredata). Everytime i was in NotificationViewController i retrieved from DataBase (Coredata) and when i want to clear them i-e on Reading , deleted that particular Notification form DB.

thats how you should do it.

OR https://developer.apple.com/library/ios/releasenotes/General/WhatsNewIniOS/Articles/iOS7.html#//apple_ref/doc/uid/TP40013162-SW1 Apple says in iOS 7 user can send "silent" push notifications—that is, notifications that do not display alerts or otherwise disturb the user. By receieving this type "silent" in method application:didReceiveRemoteNotification: do this [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; [[UIApplication sharedApplication] cancelAllLocalNotifications];

Wanda answered 14/1, 2014 at 21:33 Comment(7)
Hmm... But seems like when Google and Facebook do it, they do it without me even touching the app. I'm on the lock screen--and I can see the notifications going away. That core data handling only works when the app is open as far as I know?Studding
You want to do it when you select a particular Row in UITable ?Wanda
No. I see push notifications on my lock screen. When I do something on the website, the push notifications on my lock screen disappear. That's how it was implemented in these other platforms.Studding
developer.apple.com/library/ios/releasenotes/General/… says in iOS 7 user can send "silent" push notifications—that is, notifications that do not display alerts or otherwise disturb the user. By receieving this type "silent" in method application:didReceiveRemoteNotification: do this [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; [[UIApplication sharedApplication] cancelAllLocalNotifications];Wanda
I don't think this is for a silent push. I'm talking about clearing all of the current push notifications which haven't been clicked on.Studding
The function you are referring to only gets called when the user interacts with that notificationStudding
You cannot interact Silent notifications. but in didReceiveRemoteNotification: you can clear/cancel every Notification. You just need to check if Notification is silent then do this [[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0]; [[UIApplication sharedApplication] cancelAllLocalNotifications];Wanda
S
2

Just ask your backend to send a push with the payload:

{
    "aps" : {
        "badge" : 0
    },
}
Subequatorial answered 29/1, 2016 at 3:39 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.