重置iOS应用程序徽章

重置iOS应用程序徽章,ios,xcode,ios7,parse-platform,push-notification,Ios,Xcode,Ios7,Parse Platform,Push Notification,嗨,我目前正在开发一个应用程序,它使用推送通知。我已经成功地将其用于解析,并且我的应用程序正在接收通知。我的问题不是当我打开应用程序时如何重置徽章,因为我已经在使用此代码时获得了徽章 - (void)applicationDidBecomeActive:(UIApplication *)application { [UIApplication sharedApplication].applicationIconBadgeNumber = 0; } - (void)application:(

嗨,我目前正在开发一个应用程序,它使用推送通知。我已经成功地将其用于解析,并且我的应用程序正在接收通知。我的问题不是当我打开应用程序时如何重置徽章,因为我已经在使用此代码时获得了徽章

- (void)applicationDidBecomeActive:(UIApplication *)application
{

[UIApplication sharedApplication].applicationIconBadgeNumber = 0;

}

- (void)application:(UIApplication *)application
didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken
{
// Store the deviceToken in the current installation and save it to   Parse.
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
[currentInstallation setDeviceTokenFromData:deviceToken];
[currentInstallation saveInBackground];
}

- (void)application:(UIApplication *)application
didReceiveRemoteNotification:(NSDictionary *)userInfo {
[PFPush handlePush:userInfo];
}

该代码将从应用程序中删除徽章,但当我发送另一个通知时,数字现在是2而不是1。如何修复此问题?

[UIApplication sharedApplication].ApplicationOnBadgeNumber=0不帮助清除解析中的标记。我只是阅读了解析和文档

徽章:iOS应用程序图标徽章的当前值。在PFS安装上更改此值将更新应用程序图标上的徽章值。更改应保存到服务器,以便用于将来的徽章增量推送通知

徽章:(仅限iOS)应用程序图标右上角指示的值。可以将其设置为值或增量,以便将当前值增加1

清除徽章您需要执行以下代码:

- (void)applicationDidBecomeActive:(UIApplication *)application {
  PFInstallation *currentInstallation = [PFInstallation currentInstallation];
  if (currentInstallation.badge != 0) {
    currentInstallation.badge = 0;
    [currentInstallation saveEventually];
  }
  // ...
}

对于任何想知道如何在swift中重置徽章的人,这里有一个swift版本@nitin的答案

func applicationDidBecomeActive(application: UIApplication) {
    var current: PFInstallation = PFInstallation.currentInstallation()
    if (current.badge != 0) {
        current.badge = 0
        current.saveEventually()
    }
}

请在通知中输入设置徽章值的代码。好的,这是通过解析完成的,但我认为这是代码。问题中添加的代码是否存在类似于
[UIApplication sharedApplication].applicationIconBadgeNumber=设置徽章值
的代码,谢谢,但Nitin Gohel的答案有效!我建议使用saveInBackground而不是SaveFinally。我正在构建一个rect本机应用程序,即使我使用此代码,它也不起作用。有什么建议吗?