重新安装应用程序时如何清除通知标记计数

How to clear notification badge count when reinstall the app

我已经为我的 iOS 应用程序集成了苹果推送通知。我的问题是,当我重新安装该应用程序时,甚至在登录该应用程序之前,就会显示之前的通知徽章计数。我怎么解决这个问题?请帮助我。

您是否尝试过从多任务菜单中关闭该应用程序并再次启动它?请致电此处

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

其他

它只会在启动应用程序时被清除。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

[[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];

return YES;
}

选择-2

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    if (launchOptions != nil)
    {
        NSDictionary* dict = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dict != nil)
        {
            NSLog(@"Launched with APNS: %@", dictionary);

            [self clearAPNSNotifications];
        }
    }

    return YES;
}

- (void)application:(UIApplication*)application didReceiveRemoteNotification:(NSDictionary*)userInfo
{    
    NSLog(@"Received APNS : %@", userInfo);
    [self clearAPNSNotifications];
}

 - (void) clearAPNSNotifications {
[[UIApplication sharedApplication] setApplicationIconBadgeNumber: 0];
[[UIApplication sharedApplication] cancelAllLocalNotifications];
}

针对 iOS 7 和 iOS 8 以及 iOS 9 进行了更新,来自 Apple 的文档:

On iOS 7 and later, The first time a push-enabled app registers for push notifications, iOS asks the user if they wish to receive notifications for that app. Once the user has responded to this alert it is not presented again unless the device is restored or the app has been uninstalled for at least a day.

If you want to simulate a first-time run of your app, you can leave the app uninstalled for a day. You can achieve the latter without actually waiting a day by following these steps:

Delete your app from the device. Turn the device off completely and turn it back on. Go to Settings > General > Date & Time and set the date ahead a day or more. Turn the device off completely again and turn it back on.

对于 iOS 5 和 iOS6:

Reset the push notifications permissions alert by restoring the device from a backup (r. 11450187). Here are the steps to do this efficiently:

Use the Xcode Organizer to install your app on the device. The key is to install the app for the first time without running it. Use iTunes to back up the device. Run the app. The push notifications permissions alert will be presented. When you want to reset the push notifications permissions alert, restore the device from the backup you created in the first step.

更多详情请参考此linkhttp://developer.apple.com/library/ios/#technotes/tn2265/_index.html