I am using parse to handle my push notifications. I send a notification to my app, with option "Increase Badge Number" selected. It sets the badge at 1. Then I call this in the app:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
This works as expected, clears badge number.
Then I send another push notification in parse with "Increase Badge Number" selected again. However this time the badge on the app shows 2. Again the code clears the badge, but I want it to show 1 at that point, am I missing some code? Or is this a parse issue?
You're clearing it in iOS, but you're not changing the value for the badge on the Installation object on Parse. So, if you just call increment, yeah the number will be bigger than you expect.
You could add this to your above example:
[[PFInstallation currentInstallation] setObject:#0 forKey:#"badge"];
[[PFInstallation currentInstallation] saveEventually];
So that the badge number gets cleared out on the Parse side and future increments will do what you expect.
Related
I am setting 0 application icon badge number, as below as opening app.
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
but as server sends increment while app is in background of killed state, it never again starts with ZERO.
Say, if it is 2, than will be 3, than will be 4 on every push. If I open App and set it ZERO, and go back, it shows nothing on iCON, but as server sends, it starts from 5.
In short, it keeps existing counter.
How can I fix this issue. I have iOS 10.1, and Xcode 8.1
Thanks.
The payload that comes from server already has a badge number that will be setted, so no matter what it was previously. Only badge number that you get in payload matters.
What you need to do is add some custom logic to the place where you call [UIApplication sharedApplication].applicationIconBadgeNumber = 0; so you can reset server badge count each time you activate the app.
I use UILocalNotification to show alerts.
I need to show two alerts 2 hours apart.
Right now, my code displays two different notifications on lock screen.
Assume, alerts/notifs were not touched by user during this period.
Is it possible for me to
Either remove the first shown notification from lock screen
Or update the first notification with the contents of second alert/notifcation.
To my understanding, you cannot modify a UILocalNotification once it has been scheduled.
To dismiss an already fired UILocalNotification, try calling the [[UIApplication sharedApplication] cancelAllLocalNotifications];
and then re-add those that were not yet fired.
I am working on an app that can receive Push-Notifications.
When a notification is received, I need to change the number of the icon's badge and increment it.
Those notifications are stored in a UITableView in my app.
When a row is pressed, this means that the notification has been read so I want to decrement the badge.
I am new to push notifications and badges and I really couldn't find any efficient way to do it
any solutions ?
Thank you.
You can't automatically increment a badge from a notification. Your notification payload must contain the badge property that will be set to the exact value you want for your badge.
To set the badge value from within your app, you can use:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:someInteger];
If you want to increment the badge by one every time you receive a notification, you need to keep track of your user's badge server-side.
For example, if you send 3 notifications to an user, you will have a badge column in your database for this user with 3 as a value. If the user opens his app and taps one of the notifications, your app will have to set the badge icon to 2 and send a request to your server to decrease the database value to 2.
TL;DR: There is no such thing as a badge:+1 or badge:autoincrement in a notification's payload. You have to keep track of the badge's value server-side.
I'm using push notifications on my iOS app and everything is working great.
The icon badge is working and when I open the app I clear it with this code:
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
But before clearing it I would like to find out what is the badge count to make some changes on the app according to the number of notifications the user has when opening the app.
Is it possible to do get this number?
Thanks!
[UIApplication sharedApplication].applicationIconBadgeNumber
Try
I don't want to see the badge number on the app icon. but I want to keep the notifications in notification center.
How to achieve this?
The following doesn't work as it clears all the notifications in the notification center.
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
The following doesn't work as well, as it only remove the badge counter after the app is opened.
[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
I am thinking is it possible to push a negative badge number with a value of -1?
You should be able to specify what the desired badge number is when you send the push notification. From Apple's Local and Push Notification Programming Guide, if you send a number with "badge" as the key.
The number to display as the badge of the application icon. If this property is absent, the badge is not changed. To remove the badge, set the value of this property to 0.