Skip to content

Instantly share code, notes, and snippets.

@vseow
Created August 7, 2015 20:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vseow/afebffafe93d767c6d7e to your computer and use it in GitHub Desktop.
Save vseow/afebffafe93d767c6d7e to your computer and use it in GitHub Desktop.
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