Created
August 7, 2015 20:54
-
-
Save vseow/afebffafe93d767c6d7e to your computer and use it in GitHub Desktop.
Set Badge Notification Number on App Icon (iOS)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- (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