Reputation: 277
I am integrated APNS in my app, The requirement is to maintain notification count when app in background. For example we got notification in background in there is key counter count , i,e changing dynamic in every notification, Can it possible to handle in iOS when app is background or app has forcefully closed.
Upvotes: 4
Views: 10324
Reputation: 2096
This is the APNS payload from back end server.
{
"aps" : {
"alert" : "You got your emails.",
"badge" : 9,
"sound" : "bingbong.aiff"
},
"acme1" : "bar",
"acme2" : 42
}
EDIT: if you want to reduce the badge count on your own.Decrement the count and update it yourself.as follows
NSInteger numberOfBadges = [UIApplication sharedApplication].applicationIconBadgeNumber
numberOfBadges -=1;
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:numberOfBadges];
or else make the count to 0, so that badge icon will be disappeared.Add the below code in ** applicationDidBecomeActive**
application.applicationIconBadgeNumber = 0;
Upvotes: 8
Reputation: 7373
For managing the notification counter you have to setup functionality at server. lets take Facebook
example if you are not reading the new notification the counter keep increase by one and once you click on notification it comes back to zero. so whenever you read new notification it also managed on server side whether is user opened it or not.
lets say there are 3
notifications user di't see than for next one counter will be 4
.
And once your receive the count from server with update, handle it like if all updates are viewed application badge counter set to 0
this is my understanding as i have implemented the same in my iOS
application if anyone has any good solution. please suggest.
I hope this picture(source google) will give the complete understanding.
Upvotes: 3