I have an app that receives push notification. I would like to add the badge with the right value near a button inside the application menu (do you remember the old Facebook app?).
I'm trying to get the badge value from the notification in the AppDelegate, save it in NSUserDefault to use it in other view controllers.
NSString * badgeValue = [[userInfo valueForKey:@"aps"] valueForKey:@"badge"];
NSUserDefaults * defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:badgeValue forKey:@"badge"];
[defaults synchronize];
The problem is that if I try to put the value in a label the app crashes
'NSInvalidArgumentException', reason: '-[__NSCFNumber isEqualToString:]: unrecognized selector sent to instance
Xcode makes me save badgeValue in a string but when I put the string in the label it says is not a proper string
if ([badgeValue isKindOfClass:[NSString class]]) {
NSLog(@"it is string !!!!!!!!!!!!!!!");
// treat it as a string object
} else {
NSLog(@"it is not a string !!!!!!!!!!!!!!!");
// treat it as a number object
}
By debugging I see that badgeValue is not a real string but __NSCFNumber and if I try to convert it in a string the return value is a long strange number. I searched everywhere for a way to get the badge value of the notification but the only option I can think of is a php query...Any idea?