Reputation: 108
Im trying to change count of Push notifications in AppDelegate.
I made a property and synthesise it in AppDelegate.h for store NSDictionary with notifications data.
@property (strong,nonatomic) NSMutableDictionary *pushArray;
When I receive notifications I do it:
- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
{
_pusharray = [[userInfo valueForKey:@"aps"] valueForKey:@"badges"];
}
Im getting notification in another file (for example mainViewController) well but I can't remove item in _pusharray. Im makin it like that:
- (IBAction)touchMaenuButtons:(id)sender {
NSUInteger index = [self.menuButtons indexOfObject:sender];
NSMutableDictionary *pushArray = [(AppDelegate *)[[UIApplication sharedApplication] delegate] pushArray];
NSString *key = [NSString stringWithFormat:@"%lu",(unsigned long)index];
UIButton *button = [_badges objectAtIndex:index];
[button setTitle:@"" forState:UIControlStateNormal];
button.hidden=YES;
[pushArray removeObjectForKey:key];
}
In the end string i receive error:
* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSDictionaryI removeObjectForKey:]: unrecognized selector sent to instance 0x145a78a0'
Please somebody give me answer how to correct it.
Upvotes: 0
Views: 237
Reputation: 1788
It's not a mutable dictionary
you should use the initialiser below to make the dictionary mutable.
_pusharray = [NSMutableDictionary dictionaryWithDictionary:[[userInfo valueForKey:@"aps"] valueForKey:@"badges"]];
Also as a style thing don't call a dictionary an array
Also personally don't like to see this
[(AppDelegate *)[[UIApplication sharedApplication] delegate] pushArray];
If you need this kind of functionality create your own singleton don't overload the app delegate with this king of thing. The app delegate is for the system to talk to your app you should try and avoid putting your app logic in here if possible.
Upvotes: 2