The following text reproduced from: http://www.itdadao.com/articles/c15a380661p0.html
update of the 2017-10-12 number: IOS 11 This feature is still useful ... Directly to the Applicationiconbadgenumber assigned to-1 on the line. This line of code only takes effect on iOS 11.
[UIApplication sharedapplication].applicationiconbadgenumber =-1;
If you want to be compatible with ios10,8,9. Or use the old way before, as follows:
Careful students will find such a situation, when we execute the following code, AppIcon above the number is eliminated, but the notification bar all the push will also be cleared. You can't see it until you see the push.
[UIApplication sharedapplication].applicationiconbadgenumber = 0;
So how to let the numbers disappear, but also keep the notification column push information. Finally, a solution is found on the StackOverflow, which is implemented in the following ways:
First add one of the following methods:
-(void) resetbagenumber{uilocalnotification = [[*clearepisodenotification
ALLOC] init]; /* IOS 11, directly set the Badgenumber does not take effect. A silent push is first made (i.e. no soundname and alert). It doesn't matter if the original app's badge is 0.
For local push0 is not operation. Back in Applicationiconbadgenumber =-1 * * Clearepisodenotification.applicationiconbadgenumber = [UIApplication Shared
Application].applicationiconbadgenumber;
[[UIApplication sharedapplication] schedulelocalnotification:clearepisodenotification];
Clearepisodenotification.applicationiconbadgenumber =-1;
[[UIApplication sharedapplication] schedulelocalnotification:clearepisodenotification]; }
You can use the above method to successfully eliminate the appicon above, but keep the push message in the notification bar. Why use this way to succeed.
This is actually using a bug in the Apple system. Open a remote push for a second and send a local push, this local push does not carry any information, but Applicationiconbadgenumber is equal to-1, see API said if Applicationiconbadgenumber is 0, It is equivalent to do not do any processing, but equal to 1 words to do processing, but the system can not show-1, only do not show. Not showing is not equivalent to placing the Applicationiconbadgenumber at 0, because the applicationiconbadgenumber=0 will automatically eliminate all notifications from the notification bar about the application. This makes it seem like we're doing our function. It's also a bug in the iOS system.
And this method, the disappearance of badge also bring animation Austrian
Third, the final code is as follows:
The push quantity is not displayed on the AppIcon, but the method to keep push notifications in the system notification bar
-(void) resetbagenumber{
if (is_ios11_later) {/
*
IOS 11, Directly set Badgenumber =-1 is in effect
/
[UIApplication sharedapplication].applicationiconbadgenumber =-1;
} else{
uilocalnotification *clearepisodenotification = [[Uilocalnotification alloc] init];
Clearepisodenotification.firedate = [NSDate datewithtimeintervalsincenow: (0.3)];
Clearepisodenotification.timezone = [Nstimezone defaulttimezone];
Clearepisodenotification.applicationiconbadgenumber =-1;
[[UIApplication sharedapplication] schedulelocalnotification:clearepisodenotification];
}
#define Is_ios11_later ([[Uidevice Currentdevice] devicesystemmajorversion] >= 11)