xmarston
xmarston

Reputation: 883

Clear a single notification with PushPlugin for Cordova in iOS

In an iOS app that I developed with Cordova I'm using the PushPlugin, I'm facing a problem (maybe it's not be a problem for other people) that when you have multiple notifications of the app in the notifications center if you click one (the app starts) of them, then you take a look at your notification center again and you won't see any remaining notification.

I took a look at the plugin code and I found that in the function applicationDidBecomeActive of the file AppDelegate+notification.m contains this line:

application.applicationIconBadgeNumber = 0;

Could be this line the problem? If not, how I can edit the code to only clear the clicked notification?

I opened an issue in the plugin repository days ago but I did not received any response from the developer/s.

Upvotes: 0

Views: 747

Answers (1)

jcesarmobile
jcesarmobile

Reputation: 53351

The problem is how iOS 7 and previous versions manage the notifications, there is no way to delete just one notification, you can delete all or none, but not one, it's not a plugin bug and there is nothing you can do

it seems that on iOS 8 apple automatically removes the notification when you click it, so you just don't have to execute this line on iOS 8: application.applicationIconBadgeNumber = 0;

You can use this Preprocessor Macro

#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)

and check the version to remove all the notifications if the device have a previous version

if (SYSTEM_VERSION_LESS_THAN(@"8.0")) {
    application.applicationIconBadgeNumber = 0;
}

Upvotes: 1

Related Questions