Todd Hopkinson
Todd Hopkinson

Reputation: 6893

How do I decrement the PFInstallation for Parse in my iOS app?

I am using Parse and PFInstallation to increment my app's badge count based on notifications from Parse. I need to be able to decrement that number as well - not just reset it; I'm looking for the same behavior with iOS Messages or Mail app badging. Each time you read a mail item or message, the app's badge decrements by the number of items you've viewed.

How can I achieve this in my iOS app with Parse and PFInstallation? PFInstallation has the concept of incrementing, but what about decrementing?

Upvotes: 0

Views: 97

Answers (1)

Josh Gafni
Josh Gafni

Reputation: 2881

Unfortunately, you cannot use Decrement like you can Increment. However, you can set the badge number to a specific value two different ways.

Update the Installation

PFInstallation *currentInstallation = [PFInstallation          currentInstallation];
if (currentInstallation.badge != 0) {
    currentInstallation.badge -= 1;
    [currentInstallation saveEventually];
}

Update Via Push

Before creating the push, look at the current badge number in your database, and send the value - 1.

NSDictionary *data = @{
     @"alert" : @"Your message",
     @"badge" : @<Decremented Value>,
};
PFPush *push = [[PFPush alloc] init];
[push setChannels:@[ @"Your Channel" ]];
[push setData:data];
[push sendPushInBackground];

Upvotes: 2

Related Questions