How can I increment app icon badge when multiple local notifications fire? - iphone

I'm trying to understand the applicationIconBadge property of UILocalNotification. I can only set an explicit badge value, I can't specify I just want it incremented when the notification fires.
http://developer.apple.com/iphone/library/documentation/iPhone/Reference/UILocalNotification_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40009565-CH1-SW11
I'm trying to accomplish the following: one notification fires, the user ignores it, a second notification fires, the user ignores it. At this point I would like the badge to be 2, but as far as I can tell there aren't any methods I can implement to handle the notification firing, but being ignored. My didReceiveLocalNotification event will not be called. That means there is no way for me to manipulate the badge number, aside from the UILocalNotification.applicationIconBadge property, which has no "just increment it" functionality.

One way I can think of doing this is to maintain a count internally, and when you create each notification, assign it the right badge property. So if you know that notification 1 will fire before notification 2, then assign the first one 1, and the second one 2. This will take care of your issues as stated above.
If the user launches the app after notification 1 but before notification 2, and gets rid of the first '1' badge, then you can then reassign the badge properties for all the remaining notifications. It's more work than doing a straight += 1, but unless someone else has a better idea, I think this is the way to do it.

Check out this category I made for UILocalNotification: GitHub UILocalNotification

I have reason to believe that the implementation of applicationIconBadgeNumber is buggy, or at least not according to what it has been described to do in the documentation.
I've filed a bug report/enhancement at http://bugreport.apple.com/
You may take a look at my report archived at Open Radar: http://openradar.appspot.com/radar?id=767401
Meanwhile, I have also resorted to a similar hackery just to achieve this simple behaviour.
According to Marco, developer of Instapaper, Apple prioritizes enhancement and feature requests partly based on how many developers are requesting them.
If this feature is important to you I urge you to file a report as well.

Related

How to update body of repeated local notification in iOs 10?

I created a local notification with Swift 3. The problem is that I want to change the body of local notification.
For example:
- There are 15 left issues.
20 minutes later:
- There are 10 left issues.
Can anybody help me, please?
After research I can almost confirm that it is not possible to update the repeated notification without app being foreground.
When you schedule a repeated push notification, the title and body is already set. In order to change the tile and body we will need to catch notification. However, according to this answer, notification service extension only works for remote notification but not local notification.
SO... How to achieve this using work arounds?
I can think 2 ways to do this.
Schedule approx 60 notification manually and preset the title and body. However, in your case, it is still not possible because you will never know how many issues left after 20 mins?? If you can pre-calculate, then you can use this solution. The disadvantage for this is it can only schedule for 64 local notifications and each time when push a local notification it creates a new delivered notification stay in the system which will spam user's notification center.
The second way is to use Notification Content Extension. NOTE: You can still not modify the title and body for the notification delivered. However, you can create a custom screen when user force touch the notification bar. Maybe the subtitle can be something like force touch to see how many issues left and implement a custom screen to show the number of issues when user force touch on it.
I am still experiment on this. There's one more option that I want to suggest is you can always do a remote push notification if issue number changes, which might be a better user experience in your case instead of pushing a repeated one every 20 mins.
Useful Reference
Here is a tutorial I found useful for Notification Content Extension.
To understand more, here is a link to WWDC of introducing notification service extension and notification content extension.
I believe you can use Notification Content Extension. You kinda have much more freedom since you are working with a view controller. I would use that!

Handle timeout of GNotifications in Gnome?

My program needs to react to the user not taking any action on a GNotification.
More specificially, a piece of data is written to the database only if the user does not press the "undo" button on the notification sent after the data's creation. My target deployment scenario does have notifications enabled and a real timeout value.
To be precise: Moving the notification "away" / deleting it should also count as such a timeout.
1) Is there a built-in way to 'listen' to notification timeouts?
2) If not, how could I still implement similar behavior?
I would use the D-Bus org.freedesktop.Notifications interface. Although it is still a draft specification, it does appear stable. My experience accessing the D-Bus interface using Vala has been that it is easier to use and gives the full feature set of the specification. GNotification doesn't seem to be as feature complete.
From the draft specification you will see there is an expire_timeout argument of the org.freedesktop.Notifications.Notify method. That should fit your time out requirement, although I've not used it personally. There is also a org.freedesktop.Notifications.NotificationClosed signal that will allow your program to be notified when the notification is closed, including because of a time out or if it was dismissed by the user.
This post about the screen lock re-design for GNOME Shell 3.10 might give some indication of what notifications are capable of. The post includes some screenshots of notifications appearing in the lock screen.

Handling Invitations for Programmatic Turn-Based Game

Thanks to the updates to GameKit API in iOS 6, I am finally able to implement my turn-based board game the way it should be, complete with turn timeouts and better programmatic creation of matches. However, I am running into an issue that I cannot seem to solve. My desire is to have Game Center running entirely invisible to the end-user, so that everything is programmatic and uses my own custom interfaces.
Therefore, I use my own custom table view to display matches, not the default GKTurnBasedMatchmakerViewController. Right now, I have no problem displaying open matches using the -loadMatchesWithCompletionHandler: method. I also use a custom screen to create a match, with a direct creation for auto-match (not a problem) and a table view that loads Game Center friends of the localPlayer for invitation. Since the playersToInvite attribute can now be filled with playerID's, this is possible in iOS 6.
My main problem is handling the invitation on the recipient's side. Lets say I invite Bob to play my game in a two-player match. Right now I can't seem to find a notification for a new invite on Bob's end. The -handleTurnEvent: only gets called for existing matches or if the banner notification is touched (which I can't guarantee the user will do), and -handleInviteFromGameCenter: does nothing for me in this case.
The only way I have come up with to detect new invites and thus update my custom game view controller is to call the -loadMatchesWithCompletionHandler: method and check for new matches in which lastTurnDate of the invited participant is nil and against an existing array of open matches. I run this check about every 10 seconds in the background since I can't find a notification in GKTurnBasedEventHandler that is called when a new invite is received. Please help!
EDIT: In the end, I have just implemented a pull-to-refresh functionality. There is no way without implementing polling or some other method that would just waste the user's data on their phone, so on demand refreshing is the most ideal solution in my opinion.
Please see this : GKInvite Reference and more specifically inviteHandler.
You just need to register an inviteHandler which will be called after Bob accepts the invite in GK/GC.
T.

UILocalNotification repeatInterval + applicationIconBadgeNumber

I'm trying to schedule repeating local notifications and set the application badge number to the actual number of notifications that have been scheduled so far at any given moment.
Since there's apparently no way to set a different badge number for each occurrence of the notification, I can see only 3 solutions:
Ignore the repeatInterval property of the notification and schedule separate notifications myself (see here). The thing is, since the system holds only 64 notifications per application, I may miss notifications if the user taps "dismiss" too many times, especially if several notifications are active.
Show an incorrect badge number (1 for each unique notification, regardless of the number of times this notification has been repeated so far).
Not use a badge at all.
Am I missing something, or are these the only 3 options?
Looks like those are your options, since the badge number property of an UILocalNotification does not increment the current applicationIconBadgeNumber but just set it's these are your options.
Also keep in mind that when going with option 1 your have a maximum of 64 notifications that can be set, but you know that already ;)

Send notification each day with different information

i want to send a notification each day at the same time with different information. I got no problem with showing the alert when i want to. The problem is what to show. First i tried to schedule one alert every day with different information in them, but that seems really inefficient. Then i tried with
-(void)application(UIApplication*)app didReceiveLocalNotification:(UILocalNotification *)Notif{}
but found out that it runs when the application is running in foreground only.
Is there any way to provide an array or something like it with the alert and tell the alert to get its body from the array with different index for different days?
Or should i do it with some notification that can run when the app is in background mode and the alert show and make a new alert?
All information must be provided when you schedule a local notification, so no, a notification's body cannot be sourced from an array as you described. If users are likely to open your app often and you know notification content in advance, perhaps you could ensure that x notifications are always scheduled (could be achieved by inspecting UIApplication's scheduledLocalNotifications).
This solution isn't ideal though, as it relies on users opening your app on a (somewhat) regular basis. I think push notifications are probably your best bet, but that requires access to a server, etc.
Yeah push could prob be the solution. But i dont have a server for that. The users will most likeley not open it any more after they have opened it the first time to activite the local-messages. So then this isnt really possible to do without push. when i tried a for-loop to schedule 250 days with different text each day it took about 2 minutes on iphone 4 so its not duable.