UILocalNotification shows 400 badges - iphone

I am scheduling a UILocalNotification for an interval. Basically I wanted a notification to be triggered every x days on this app. So the way I did it is to schedule a bunch of notifications at once. So say it's every 2 days, then I do a calculation of the dates every 2 days from now for a year. I am not sure if this is the right and most efficient solution to it, but from researching online, this is what I get I need to do.
The issue is that when the notification fires and I open the app, the badges count goes up to 500, which I think is the number of all future notifications I've scheduled. How is this even possible> Shouldn't the badge only show the number of notifications before the timestamp?

The badge number does not show a number of notifications, but the badge value that you set as notification payload.

Related

iOS: Notification Badge Number does not reset

I want to reset the notification badge number whenever the app is opened. This works perfectly fine calling
application.applicationIconBadgeNumber = 0
UNUserNotificationCenter.current().removeAllDeliveredNotifications()
However, when I one ore more new notifications come in, the icon badge number again goes to 42 no matter how many notifications come in.
Does anyone know how to fix this?
You can follow one of the following for achieving this,
You can store notifications received in your database and when user opens app, you can get the count of unread notifications and update the count.
If you are targeting single users then, you can get the delivery of Push notifications using https://stackoverflow.com/a/50044201/5084797 and then when the notification is opened you can pass notification Open event to server. So the next time the server sends push notification, they can just check for the difference in Deliver and Open and send that count in badge. If user has cleared all notifications from Notification centre without opening them. In that case as soon as App opens you need to update that at server, Else you might be getting wrong count from server.

UILocalNotification multiple firing

I schedule a UILocalNotification at at specific date, and the notification is fired correctly, But the problem is that I receive multiple alerts at random dates for same notification even though the notification is not repeated (repeatInterval = 0 ).
Another note, when I receive the notification at first time , it appears correctly in notification center, but later when I receive the multiple alerts nothing updated in notification center.
Please note that this event is repeated daily, but the notification not get repeated.
Any solution for this issue?
I expect you are never calling:
[[UIApplication sharedApplication] cancelAllLocalNotifications]
These notifications appear to be "old" notifications that haven't been cancelled and are still due to fire. Did you ever have a repeat interval? Some of these notifications could be repeated from very old notifications

changing the icon badge number when local notification fires

I need to increase the icon badge number everytime a local notification gets fired to inform the user that there is one more question he needs to answer. When the user answers a question of any sent notification the icon badge number is beeing reduced by 1. I only have one-time notifications, no recurring.
Since the app is not running when the notification fires I do not have any idea how to increase the icon badge number at that time. While there is no problem to decrease the number when the user answers a question - since this is done within the app.
Is there any possibility - maybe similar to registerForRemoteNotificationTypes for push notifications?
Many thanks!
The UILocalNotification class has a property applicationIconBadgeNumber of type NSInteger, which you can set, when scheduling the local notification.

UILocalNotification issue with past dates

I am making a reminder app, if there aren't a million out there.
I let the user specify a time to remind him of a to-do task.
So lets say the user specifies that he needs to be reminded at 9:00am every Monday.
When he closes the app and its goes in the background I create a UILocalNotification fire time.
at 9:00am on next Monday the user gets the notification.
If he launches my app and adds another reminder for some other day/time (not important) and closes my app by clicking on the home button then he gets a notification right away.
This is because the first notification was set to past Monday date
How can I avoid this yet still deliver a notification next monday?
I found this by googling
"If you specify a date that is in the past (or nil) the notification is delivered immediately. "
So, here's what I got from your question:
User makes repeating event for 9:00AM every Monday
You schedule a single local notification for the next occurring Monday at 9:00AM
One Monday at 9:00AM occurs; the users's event fires
User makes another arbitrary event
The users's first event fires, as if it was Monday at 9:00AM, presumably because Monday at 9:00AM has already happened once
In order to resolve this, you want to make sure you're doing both of these things:
Make sure you're releasing the UILocalNotification.
//Manual Memory Management
[yourLocalNotif release];
//Automatic Reference Counting
yourLocalNotif = nil;
Make sure rescheduling your repeating events for the next occurring time.
If this isn't quite what you're looking for, post some code and I'll try and reevaluate :)

Is it possible to schedule push notification time ? (iPhone SDK)

I want to schedule push notification after some time or say after 2 days 15 hours. So after 2 days 15 hours a notification will be sent to a device.
Is it possible ? How ??
Since a push notification originates from a server and not the phone itself you can schedule anything the provider makes available. You will have to check with your notification service provider what they make available.
However if you just need to schedule a future alert on the phone itself, you can use the UILocalNotification class. This will just kick off a notification on the device once the timer expires.