Skip to content

Instantly share code, notes, and snippets.

@vseow vseow/badge.m
Created Aug 7, 2015

Embed
What would you like to do?
Set Badge Notification Number on App Icon (iOS)
- (void)application:(UIApplication *)application didReceiveRemoteNotification: (NSDictionary *)userInfo {
NSLog(@"userInfo:%@",userInfo);
badge_value+=[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"]intValue];
NSLog(@"Total badge Value:%d",badge_value);
for (id key in userInfo) {
NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
}
[UIApplication sharedApplication].applicationIconBadgeNumber = badge_value;
// To decrease
[UIApplication sharedApplication].applicationIconBadgeNumber = badge_value - 1;
}
// Unread notifications in Notification Center
NSDictionary *userInfo = [responseObject objectForKey:@"unread_notifications"];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(newNotification:) name:@"unread_notifications" object:nil];
-(void)newNotification:(NSNotification *) notification{
NSDictionary *userInfo = notification.userInfo;
if ([[NSString stringWithFormat:@"%@",userInfo] isEqualToString:@"0"]) {
} else {
NSString * badge = [NSString stringWithFormat:@"%@",userInfo];
[UIApplication sharedApplication].applicationIconBadgeNumber = badge.intValue;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.