【问题标题】:Reset iOS app badge重置 iOS 应用徽章
【发布时间】:2014-06-14 11:31:53
【问题描述】:

您好,我目前正在开发一个使用推送通知的应用程序。我已经成功地让它与 Parse 一起工作,并且我的应用程序正在接收通知。我的问题不是当我打开应用程序时如何重置徽章,因为我已经使用这段代码了。

- (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].applicationIconBadgeNumber=setting badge value的地方代码
  • 谢谢,但 Nitin Gohel 的回答奏效了!

标签: ios xcode ios7 parse-platform push-notification


【解决方案1】:

[UIApplication sharedApplication].applicationIconBadgeNumber = 0; 在解析中没有帮助清除徽章。我刚刚阅读了 Parse Push notification Guide Documentation 和文档说。

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

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

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

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

【讨论】:

  • 我建议使用 saveInBackground 而不是 saveEventually。
  • 我正在构建一个 rect 本机应用程序,即使我使用此代码它也不起作用。有什么建议吗?
【解决方案2】:

对于正在寻找如何在 swift 中重置徽章的任何人,这里是 swift 版本@nitin 的答案。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-25
    • 1970-01-01
    相关资源
    最近更新 更多