In my app there UITabBar items, I want the badge value of the tab bar item to be updated every X seconds, but I can't quite figure it out...
Here is my method for updating:
-(void)updateTabBadgeValue{
NSLog(@"tick");
if([PFUser currentUser]!=nil){
NSLog(@"user is not null");
UIStoryboard *mySb = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UITabBarController *myTbc = [mySb instantiateViewControllerWithIdentifier:@"tbc"];
NotificationNavigation *nn = [myTbc viewControllers][2];
NotificationViewController *nvc = [nn viewControllers][0];
[nvc awakeFromNib];
PFQuery *query = [PFQuery queryWithClassName:@"NoCo"];
[query whereKey:@"username" equalTo:[[PFUser currentUser]username]];
PFObject *noco = [query getFirstObject];
if([[noco objectForKey:@"count"] intValue] > 0){
NSLog(@"tock");
[nn.tabBarItem setBadgeValue:[NSString stringWithFormat:@"%d",[[noco objectForKey:@"count"] intValue]]];
[myTbc viewDidLoad];
[myTbc viewWillAppear:YES];
[nvc viewDidLoad];
[nvc viewWillAppear:YES];
}
}
}
and I implement this method like this:
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
[NSTimer scheduledTimerWithTimeInterval:5.0 target:self selector:@selector(updateTabBadgeValue) userInfo:nil repeats:YES];
}
but it doesn't seem to be working...my log output shows "tick", "user is not null", "tock", in that order every 5 seconds so I know the method is being called but the badge value is not being updated