【问题标题】:How to auto increment notifications badge number when receiving a push notification in iOS13在 iOS13 中接收推送通知时如何自动增加通知徽章编号
【发布时间】:2019-11-14 15:16:36
【问题描述】:

在 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)
    } 

然后我每次打开应用程序时都会清理徽章编号:

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

问题在于,latest changes in iOS 13 方法 application :didReceiveRemoteNotification:fetchCompletionHandler 仅在推送通知的属性 apns-priority 设置为至少 5 时才被调用。我们正在使用不发送的第三方推送通知服务使用该属性推送通知。

所以我的问题是:

有没有其他方法可以在收到推送通知时自动增加应用徽章编号?

谢谢

【问题讨论】:

    标签: ios swift iphone apple-push-notifications ios13


    【解决方案1】:

    您不需要唤醒应用程序并执行此操作,这将由系统决定是否唤醒您的应用程序。最好让系统处理,并在通知中包含徽章编号。

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

    【讨论】:

      猜你喜欢
      • 2013-08-26
      • 2010-12-28
      • 1970-01-01
      • 1970-01-01
      • 2021-03-01
      • 2012-06-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多