Remove the app badge at a given hour - iphone

My app uses badge to count the number of smoked cigarettes in the current day. I would like the app to remove the badge at the midnight, when a new day begins... Is it possible to do that?
I mean, doing that while the app is closed!
Thanks

Interesting question. I don't think there is an elegant way to handle this; even multi-tasking falls short of being able to wake the app to perform a task. The only thing you're allowed to do is schedule a Local Notification, but this is only allowed to increase the badge number - sending a badge number of "0" indicates "no change".
Sorry there isn't a better answer.
andrew

Couldn't you just check, on application startup, if it was already started that day, and if not, remove the badge?

Related

IOS alert in background

My question is very simple but unfortunately I don't find any answer around the Internet. I have an app alerts the user you amount is due based on invoice date in the database. The problem is how can I check periodically while the app in the background. I tried beginBackgroundTaskWithName but it expires after max 10 munites and also I tried back ground fetch but it doesn't work in proper time manner, so may be it takes a day to fetch again.
I really need your help in this.
Thanks in advance

Duplicate push notifications on iOS

This question is probably the same as Duplicate Apple APNS push notifications?, but since that one didn't get an answer, and I have some more information, I'll try to ask it again.
Steps to reproduce the problem:
Set notification center to display notifications as alerts, this will make the problem more obvious.
Make sure the app isn't running in the foreground.
Send 3 identical push-notifications in rapid succession.
Wait until the messages arrive at the phone, you will now have to dismiss the alert 3 times.
Now send 1 more notification, that isn't identical with the previous ones.
You now get that last notification, but you'll also get one of the previous notifications showing up once more. This is the problem.
If you continue to send single notifications, one of the first 3 will keep popping up when it shouldn't.
Here is a video that follow these steps, which clearly shows the problem:
http://youtu.be/TSqt8S4FY6w
We have just as Remy Gale did in the linked question above made sure that our notifications are sent in the correct way, and only once per notification. We have also tested this with both the sandbox-apns and the production-apns, both behave exactly the same.
The problem disappears if the app-badge is set to 0, which in turn removes all notifications from notification center. Removing the notifications manually doesn't help.
UIApplication *app = [UIApplication sharedApplication];
app.applicationIconBadgeNumber = 0;
But that isn't a solution.
The problem doesn't appear if all notifications contain unique text. Adding a GUID to the alert-text will make the problem disappear. Adding it to the apns-payload as a custom property or as a localized argument will however not help, so this is also not a solution.
This will probably rarely happen in a production environment with a live app, but it can happen, and when it does, it is really annoying for the users!
Does anyone know why this happen? Does anyone have a viable solution?
This Google Group for Gmail has an entry from a user who has researched the bug a bit and includes a possible workaround. According to the entry the bug is not present in iOS 5 but was introduced with iOS 6.
The workaround is simply appending a random number of Zero-width non-joiner to the title in order to assure uniqueness.
This could be an issue with the timestamp that the server is picking while sending a push notification to APNs. Pick only the latest timestamp.

Reminders app - repeat a certain reminder

I'm building a reminders app, and been really interested in how to set a reminder to repeat itself every day/every month/every hour.
Basically I want to set something to repeat, even when my app is not running. In my case a local notification fire.
Thanks!
You can set the repeat interval easily using NSCalendarUnits
notification.repeatInterval= NSDayCalendarUnit;
For more calendar units check constants on http://developer.apple.com/library/ios/#documentation/Cocoa/Reference/Foundation/Classes/NSCalendar_Class/Reference/NSCalendar.html#//apple_ref/doc/c_ref/NSCalendarUnit
You have to use Local Push Notifications, because when your App is running in background this is the only way Apple would allow you to do something:
Check this for further info: http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008194-CH1-SW1
And this is a good tutorial about it: http://www.icodeblog.com/2010/07/29/iphone-programming-tutorial-local-notifications/
Check out Apple's reference documents here on using UILocalNotifications. I believe that is what you're looking for.
You can utilize UILocalNotifications to show a local notification at a certain time or date, whenever you like.
David Linsin also has a good post on this here.
Good Luck!

Updating application badge at midnight with options: app not launched or in background, badge number can decrease

I'm reading many things about Local Notifications and the way they can help to update the app badge number.
I'd like to update this badge at midnight, and set its value to a number I can't know before midnight. So I'd like, if possible, to launch a function at midnight that would update/load some datas, check the number to display, and display it on the badge.
Of course, the number to display is not relative to the displayed number, and can be lower or greater.
This is expected to work :
- When app is in background
- When app is in foreground
- When app is not launched
would you know a way to do this, even partially ? If not possible, let say I can make things to know the badge number before midnight... Would this help you for a working answer ? This is not wanted, but if I don't have the choice to make this work, I'll plan to write tons of useless code to do this...
Unless your application fits into one of the "official" multitasking cases (VOIP, location, and background audio), the only way you're going to be able to dynamically set the badge number when your application isn't running is with push notifications... applications can't run code in response to a local notification (until the user presses the "View" button in the notification popup, at least).
See this document for everything you could ever want to know about local and push notifications in iOS.
You can't reliably ensure that your local app will run when it needs to unless you register it as a VoIP app or as requiring continuous location monitoring; either of these, in an app that's not in fact used for VoIP or navigation, will almost certainly result in an App Store rejection.
Your best bet is to send the badge as a push notification. Assuming that a server you control can know what the badge number is supposed to be, it can send a notification with just that badge value—not necessarily an alert popup or sound—to your app. Urban Airship is a good, simple way to send push notifications without having to do a lot of configuration and setup.
You very well may be able to do this. Look at the Apple Guide to running code in the background.

How do I get a codeblock to run on the iPhone once every 24 hours at midnight if my app is suspended (multitasking)

Was reading through the iOS4 documentation for multitasking, and couldn't figure it out.
I basically need to update the badge count on my app's icon after midnight each day as long as the app is running in suspended mode (with multitasking).
I know this has to be possible, just can't figure out the best way to do it.
Thanks.
iOS "multitasking" is very specific. There's an important distinction between states here:
Suspended: Your app resides in memory, but does not receive any execution time. This is really only useful for fast app switching.
Background: In a few particular cases, you can request that the OS to run your app in the background. (Playing audio, location, finishing a long task, voip.)
So, the short answer to your question is, "you can't."
Here are a couple useful links on iOS multitasking, such as it is.
Understand an Application's States and Transitions
Executing Code in the Background
You could use a UILocalNotification to set the badge (without an alert) but you can't increment the badge because you're app does not have the opportunity to execute any code when the notification fires.
You can schedule up to 64 notifications in advance, one at midnight for the next 64 days, each one setting a new badge number. It would make a lot more sense to schedule a repeating notification but since your app can't execute code it can't increment the badge number that doesn't work.