Remove push from notificationcenter after app has been opened

孤者浪人 提交于 2019-12-04 16:22:19

Clearing the badge clears the notifications from the notification center.

- (void)applicationDidBecomeActive:(UIApplication *)application {
   // Clear application badge when app launches
   [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

This only works if the number changes. So to make it work in case badge is already zero, set it to some value and clear it again after a delay.

- (void)applicationWillEnterForeground:(UIApplication *)application {
    if([[UIApplication sharedApplication] applicationIconBadgeNumber] == 0)
       [[UIApplication sharedApplication] setApplicationIconBadgeNumber:1];
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
   // Clear application badge when app launches
   [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
}

Doesn't work if you set and clear in the same method.

It is not possible to remove the notification from the notification center from within the app because in iOS5, notifications properties are displayed by apps, in :

Settings -> Notifications -> The app -> Notification Center (YES/NO).
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!