Update Badge Count For Push Notifications in ios7

后端 未结 3 1421
时光取名叫无心
时光取名叫无心 2020-12-18 13:07

am working on push notifications app but badge count is not increasing when notification comes. i have saw so many examples in stack overflow

3条回答
  •  鱼传尺愫
    2020-12-18 13:47

    You have to manage your server side when you send a notification to other user then from php side they set a counter to increment the badge & send the notification to other user after that when you open your app the badge is set to null like this :

    - (void) applicationWillResignActive:(UIApplication *) application
    {
        application.applicationIconBadgeNumber = 0;
    }
    

    & to receive the notification you set this code :

    - (void) application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {    
        NSLog(@"userInfo %@",userInfo);
    
        for (id key in userInfo)
        {
            NSLog(@"key: %@, value: %@", key, [userInfo objectForKey:key]);
        }
    
        [application setApplicationIconBadgeNumber:[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]];
    
        NSLog(@"Badge %d",[[[userInfo objectForKey:@"aps"] objectForKey:@"badge"] intValue]);
    
        NSString *message = [[userInfo objectForKey:@"aps"] objectForKey:@"alert"];
    
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Test" message:message delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    
        [alert show];
    }
    

提交回复
热议问题