Note that there are some explanatory texts on larger screens.

plurals
  1. POiphone: Set badge on a tabbarItem when receiving a PUSH message, when the app is inactive
    text
    copied!<p>I have a application that uses PUSH. But I have one problem when the application is inactive/in the background. When the PUSH messages come and the user clicks on Close, the badge is set on the application-icon.</p> <p>But I also want to set a badge on a tabBarItem. I have this code that saves the PUSH</p> <pre><code>- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo { if (application.applicationState == UIApplicationStateInactive) { //Save the PUSH until the app is active. newPush = [userInfo copy]; } } </code></pre> <p>And in:</p> <pre><code>- (void)applicationDidBecomeActive:(UIApplication *)application </code></pre> <p>I have the following code:</p> <pre><code>//Check if there is new PUSH messages. if (newPush!=nil) { //There is a new PUSH! NSInteger badge = [[[newPush objectForKey:@"aps"] objectForKey:@"badge"] intValue]; if (badge &gt; 0) { //Set badge-numbers to 'badge' [[UIApplication sharedApplication] setApplicationIconBadgeNumber:badge]; [[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:[NSString stringWithFormat:@"%d",badge]]; } else { //Set badge-numbers to zero [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]; [[[[[self tabBarController] tabBar] items] objectAtIndex:3] setBadgeValue:nil]; } } </code></pre> <p>My code for handling the PUSH when the application is active works fine and the badges are set both on the application-icon and on the tabBarItem.</p> <p>Someone know what's wrong?</p> <p>Thanks in advance!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload