简体   繁体   English

在 iOS13 中接收推送通知时如何自动增加通知徽章编号

[英]How to auto increment notifications badge number when receiving a push notification in iOS13

Before iOS 13 I was incrementing the app badge number when a push notification arrived in the method application:didReceiveRemoteNotification:fetchCompletionHandler :在 iOS 13 之前,当推送通知到达方法application:didReceiveRemoteNotification:fetchCompletionHandler时,我正在增加应用程序徽章编号:

    func application(_ application: UIApplication,
                     didReceiveRemoteNotification userInfo: [AnyHashable : Any],
                     fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
        if application.applicationState == .background {
            UIApplication.shared.applicationIconBadgeNumber += 1
        }
        completionHandler(.newData)
    } 

Then I cleaned the badge number every time the app was opened:然后我每次打开应用程序时都会清理徽章编号:

   func applicationDidBecomeActive(_ application: UIApplication) {
       UIApplication.shared.applicationIconBadgeNumber = 0
   }

The problem is that with the latest changes in iOS 13 the method application:didReceiveRemoteNotification:fetchCompletionHandler is only called if the push notification has the property apns-priority set to at least 5. We are using a third party push notification service that doesn't send push notifications with that property.问题在于,随着iOS 13 中的最新更改,只有在推送通知的属性apns-priority设置为至少 5 时,才会调用方法application:didReceiveRemoteNotification:fetchCompletionHandler 。我们使用的第三方推送通知服务不支持使用该属性发送推送通知。

So my question is:所以我的问题是:

Is there any other way that I can take to automatically increase the app badge number when receiving a push notification?收到推送通知时,我可以采取其他方式自动增加应用程序徽章编号吗?

Thanks谢谢

You shouldn't need to wake the app up and do it, this'll be left up to the system as to wake your app up or not.您不需要唤醒应用程序并执行此操作,这将由系统决定是否唤醒您的应用程序。 It's much better to have the system handle it, and include the badge number in the notification.最好让系统处理它,并在通知中包含徽章编号。

https://developer.apple.com/documentation/usernotifications/unnotificationcontent/1649864-badge?language=objc https://developer.apple.com/documentation/usernotifications/unnotificationcontent/1649864-badge?language=objc

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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