I would like to let the badge number increasing automatically when receiving push notifications, for example: if I receive two notifications let the number displays as 2, if I receive more, the number increases. And I want to let the number returns zero when I open the application. So what I am doing is the following: the code in application did finish launching
[UIApplication sharedApplication].applicationIconBadgeNumber = 0;
otherwise, the code in did Receive Remote Notification is
application.applicationIconBadgeNumber = [[apsInfo objectForKey:@"badge"] integerValue];
In the server, in the php file:
$payload = '{"aps": {"alert":"'.$message.'", "sound":"default","badge":"+1"}}';
But, unfortunately, the number doesn't incremented, please correct me if the code above is wrong, thank you per advance.
There is not option in push notifications to auto-increment the badges number. You will have to pass the number that will be shown on the badge.
Also the application:didReceiveRemoteNotification:
will only be called if the app is running foreground. Here you could calculate the new badge number, but this will not help you if you app is not in the foreground.
You will need to track the badge number server side as well.