badge number count increament - iphone

I have implemented the local notification concept, it is working properly but there is a problem in badge number it is not increamenting automatically as notifications occurs. I have got a link where solution for this problem is given but don't know how to use it in app delegate. Following is the link... If someone know how to auto increament the badge number ,please provide me some solution.
https://github.com/csheldrick/UILocalNotification
Thanku very much.

When you create your local notification then before registring it with the system add this line of code.
localNotif.applicationIconBadgeNumber = [UIApplication sharedApplication].applicationIconBadgeNumber+ 1;
and then you register you notification with the system
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
localNotif is object of UILocalNotification
Hope this helps

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification {
[UIApplication sharedApplication].applicationIconBadgeNumber=application.applicationIconBadgeNumber+1;
}
i hope it will help ful to you

Related

How to clear all the notifications from notification bar in iphone

I have to clear all the Remote/Local notifications from the notification bar when the user logs out from the app without clearing by his/her own. I'm using this code to clear the notifications but it isn't working for me this is my code:
[[UIApplication sharedApplication] cancelAllLocalNotifications];
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
It seems your code is correct. Still you can try this.
[UIApplication sharedApplication].applicationIconBadgeNumber = -1;
See this.

Application Badge

Hi guy it's possible put in the application Badge some letter?
Something like ON OFF?
[UIApplication sharedApplication].applicationIconBadgeNumber = 1;
Work but it's a number
in the Sadun's book (my last day bibble) i see
[UIApplication sharedApplication] setapplicationBadge:#"ON";
But not work, any idea?
setApplicationBadge: isn't in the UIApplication API documentation. My guess is that the method used to exist but was removed.

Push notification badges not appearing?

I'm using Urban Airship to send push notifications to my app
eg:
{"aps": {"badge": 2, "alert": "Part 2 of the August Issue is ready to download!", "sound": "default"}, "device_tokens": ["X"]}
The alert will display perfectly, however the app icon is never badged regardless of what I set "badge":# to...
Is my payload incorrect or is there extra code I'm supposed to add to my app to handle badges as well as alerts? Thanks!
EDIT:
I'm registering for push notifications like this:
// Register for notifications
[[UIApplication sharedApplication] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeNewsstandContentAvailability | UIRemoteNotificationTypeBadge | UIRemoteNotificationTypeAlert)];
I was running with a similar problem. After a few minutes of checking around. I notice that there was a problem with my server side code. I found out that badge value has to be implicitly set as an integer to get the desired result. Hope that helps anyone reading this.
set the following code in the appdelegate .m file..
-(void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{
NSLog(#"Received notification: %#", userInfo);
//[self addMessageFromRemoteNotification:userInfo];
NSString* alertValue = [[userInfo valueForKey:#"aps"] valueForKey:#"badge"];
NSLog(#"my message-- %#",alertValue);
int badgeValue= [alertValue intValue];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:badgeValue];
}
In iOS 5 there is a Settings -> Notifications. Double check that the Badge App Icon is turned on.
I assume that the app is not in the foreground when you were testing? It if is in the foreground then you have to handle badging manually.

Piling up UILocalNotifications

I'm developping an app that sends tips to users every five minutes through UILocalNotifications. The problem is that if you don't use your phone for a while, the notifications pile up and when you unlock the phone, you have to dismiss them one after the other, which can become quite annoying if you haven't used the phone for quite a while. Clicking the action button on the Alert sends you back to the application but even then, you still have to go through all the notifications.
Is there any means of dismissing all the notifications that have already been fired with a single click ?
Thanks for your help.
Miky Mike
Well, actually, I realize I made a mistake.
In order to cancel all the UIlocalNotifications at one, I just have to create this simple method : one line of code is enough :
- (void)application:(UIApplication *)app didReceiveLocalNotification :(UILocalNotification *)notification {
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}
and there you are. Thanks anyway.
Before scheduling the next alarm you better to cancel all the previous notifications and then set the new one,
UIApplication* app = [UIApplication sharedApplication];
NSArray* oldNotifications = [app scheduledLocalNotifications];
// Clear out the old notification before scheduling a new one.
if ([oldNotifications count] > 0)
[app cancelAllLocalNotifications];

setApplicationIconBadgeNumber when called multiple times does not update the badge

I am working on an application where in I have to update the badge shown in the app icon multiple times. However, what I have noted is that, the setApplicationIconBadgeNumber api just works once during the lifetime of the app. I have tries using the UILocalNotification, and it works then but, I dont want to follow that route. Have you guys faced a similar problem. If yes, any pointers?
Regards
Nitin
This is a bug in iOS. It's still present today in 6.0.1, where I just fixed it with a work-around:
// Clear app badge number. Work-around for bug in iOS.
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
Might the problem be from where you are calling it?
Wrong:
// This is only called once during application lifecycle
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}
Correct:
- (void)applicationWillEnterForeground:(UIApplication *)application {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}