Shubham
Shubham

Reputation: 1270

How access app's badge count from Notification Service Extension

I want to increase the app's badge count when app receives any push notification even if the app is quit. The badge count is not maintained on server side. So I need to update app badge count increase by 1 on receive every push notification. The only way to modify push notification payload when app is in quit state is Notification Service Extension, But we can't access the UIApplication instance from extension to get app's current badge count.

Is there any way to get app badge count from notification extension

or Is there any other way to achieve this?

Please help me out from this. Thanks!

Upvotes: 1

Views: 1585

Answers (2)

dchappelle
dchappelle

Reputation: 1710

You can set the app badge from the notification service extension by setting the given request's badge property...

bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
bestAttemptContent = <current value +1>

If you can't compute the current value you could store it in UserDefaults

Upvotes: 0

Shehata Gamal
Shehata Gamal

Reputation: 100503

There is no apis that enables you to do so , but you can workaround that by observe ring changes to a user defaults key inside the app ( that you will set inside the extension with access group suite defaults ) and change the badge as you need

Upvotes: 2

Related Questions