The Situation
I actually tried to achieve the same thing as you, managing what kind of notifications get delivered to a specific device using the notification service extension locally. However, I had to figure out it's by design that...
- ... you cannot cancel the notification via a discrete api.
- ...if you empty the content of the notification, the notification will be delivered as if the notification service extension never has been called.
This is because Apple doesn't want you to spam a user's phone with notifications (even or especially when processed in the background and not even delivered), given this could drain battery life e. g.
The Solution
You have four possible choices on what to do now:
- Use silent push. Then trigger local notifications. Note: Silent push isn't always reliable.
- Use VoIP push. This is what WhatsApp uses e. g. and it would allow for such thing as notification cancelling as far as I know. However, Apple is strict when it comes to app review: Only VoIP apps are allowed to use VoIP push (I take the guess that's why WhatsApp introduced voice calls, because they needed VoIP push for decrypting their messages in the background when the notification service extension wasn't an option yet under iOS 9).
- Handle any custom cancelling logic server-side by only sending notifications to users that ought to receive those notifications right now.
- Manipulate the notification text to something not empty that nonetheless hides the original notification text. This may be useful, if you e. g. send out a push that a pro version of your app is available at a discount currently: for existing pro users, you could just edit the text to read "Thanks for being a pro.".