Reputation: 729
I use installation, push and badge on my ios app (parse.com sdk 1.7.2.2) and I noticed something few days ago, the code that reset the badge to 0 as explained in the blog post (old one http://blog.parse.com/announcements/badge-management-for-ios/)
// Clear badge if needed
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (currentInstallation.badge != 0) {
currentInstallation.badge = 0;
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
if (!succeeded) [ErrorHandler handle:@"save installation failed" forError:error];
}];
}
does not work anymore, everything is good (no Parse error) but the badge count stay to the old value in the database
In a second time I tried the hard way, and it seems to work better for a moment:
PFInstallation *currentInstallation = [PFInstallation currentInstallation];
if (UIApplication.sharedApplication.applicationIconBadgeNumber > 0 || currentInstallation.badge > 0) {
UIApplication.sharedApplication.applicationIconBadgeNumber = 0;
currentInstallation.badge = 0;
[currentInstallation saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error)
{
if (!succeeded) [ErrorHandler handle:@"save installation failed" forError:error];
}];
}
But this is not working,
any idea?
Upvotes: 1
Views: 247
Reputation: 93
Using Parse (1.14.2), Xcode 8, and ios 10, adding:
UIApplication.shared.applicationIconBadgeNumber = 0
inside the applicationDidBecomeActive method in the AppDelegate class will also reset the badge on the parse server to zero.
Upvotes: 0
Reputation: 171
there seems to be a dependency between the installation.badge and the application.applicationIconBadgeNumber setters. Ensuring the installation is always set first seems to alleviate the issue.
let pcur = PFInstallation.currentInstallation()
print("current badge = \(pcur.badge)")
if (pcur.badge != 0){
pcur.badge = 0
pcur.saveInBackgroundWithBlock({
(succeeded,error) in
print("badge save success = \(succeeded)")
application.applicationIconBadgeNumber = 0
})
}
Upvotes: 1
Reputation: 39191
Heres my swift code and it works:
// Resets badge number in parse
var installation = PFInstallation.currentInstallation()
if installation.badge != 0 {
installation.badge = 0
installation.saveInBackgroundWithBlock(nil)
}
// Resets badge number in app
if application.applicationIconBadgeNumber > 0 {
application.applicationIconBadgeNumber = 0
}
Upvotes: 3