使用 Parse 清除徽章图标

Clear badge icon using Parse

我正在使用 Parse 进行推送通知。 发送推送时,只需在解析时选中复选框即可添加徽章图标,无需代码实现。

问题是我似乎无法在 documentation 中找到解决方案以在应用程序启动后清除徽章。

任何意见表示赞赏。

在您的 appdelegate.m 中试试这个:

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

    PFInstallation *currentInstallation = [PFInstallation currentInstallation];
    if (currentInstallation.badge != 0) {
        currentInstallation.badge = 0;
        [currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
            if (error) {
                // Handle error here with an alert…
            }
            else {
                // only update locally if the remote update succeeded so they always match
                [[UIApplication sharedApplication] setApplicationIconBadgeNumber:0];
            }
        }];
    }
}

每次都应该重置徽章。