简体   繁体   中英

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!

没有 api 可以让您这样做,但您可以通过观察应用程序内用户默认密钥的环更改(您将在扩展程序中设置访问组套件默认值)并根据需要更改徽章来解决此问题。

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM