Apple push notification badge number

后端 未结 2 1849
挽巷
挽巷 2021-02-14 17:11

I have developed server side application to maintain the badge number as increment or decrement after receiving new notification and delete after seeing notification it works fi

相关标签:
2条回答
  • 2021-02-14 17:45

    It will show until you set it to zero and you can do it with the following code:

        [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0]
    


    EDIT:
    It is more common to set the badge number as you receive the notification, in either application:didReceiveRemoteNotification: or application:didFinishLaunchingWithOptions: methods of your UIApplicationDelegate class.

    You can read more about it in the Local and Push Notification Programming Guide

    0 讨论(0)
  • 2021-02-14 17:54

    If you want to change the icon badge automatically use the following code.

        - (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo
    {
    
        application.applicationIconBadgeNumber = 0;
        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]);
    
    }
    

    We also need to change the php file. So we can get the change the icon badge automatically

    // Create the payload body
    $body['aps'] = array(
        'alert' => $message,
        'sound' => 'default',
        'id' => '135',
        'badge' => 8
        );
    
    0 讨论(0)
提交回复
热议问题