Ios 徽章数量始终为一个(云功能)
如果firebase中的节点已成功更改,则我已从云功能发送通知,但即使我发送多个通知,徽章编号也始终显示(1) 我的云代码函数(typescript): 我的Xcode代码(swift): 我的代码工作正常,完成了所有工作,但徽章编号保留在一个中。任何帮助都会很好。非常感谢。在你的云函数(typescript)中,你在徽章中发送1个,因此只会得到1个,将徽章编号更改为2或3,然后它将反映在didReceive方法中 您应该在云端功能(typescript)中加入一些逻辑,使徽章编号动态化。更改此行:Ios 徽章数量始终为一个(云功能),ios,swift,typescript,push-notification,google-cloud-functions,Ios,Swift,Typescript,Push Notification,Google Cloud Functions,如果firebase中的节点已成功更改,则我已从云功能发送通知,但即使我发送多个通知,徽章编号也始终显示(1) 我的云代码函数(typescript): 我的Xcode代码(swift): 我的代码工作正常,完成了所有工作,但徽章编号保留在一个中。任何帮助都会很好。非常感谢。在你的云函数(typescript)中,你在徽章中发送1个,因此只会得到1个,将徽章编号更改为2或3,然后它将反映在didReceive方法中 您应该在云端功能(typescript)中加入一些逻辑,使徽章编号动态化。更改此
UIApplication.shared.applicationIconBadgeNumber += 1
我知道有效负载(badge:'1')中的问题,但我不知道如何使该逻辑发挥任何帮助。如果您想通过Web服务将当前的badge编号传递给服务器,那么在发送推送通知时,您必须将该徽章编号添加+1。这不是
Swift
问题,而是typescript
问题。您的代码正在发送徽章:“1”-因此需要更新以发送正确的徽章计数。
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
let userInfo = response.notification.request.content.userInfo
print("tap on on forground app",userInfo)
Messaging.messaging().appDidReceiveMessage(userInfo)
let content = response.notification.request.content
let badgeNumber = content.badge as! Int
UIApplication.shared.applicationIconBadgeNumber = badgeNumber + 1
completionHandler()
let actionIdentifier = response.actionIdentifier
switch actionIdentifier {
case UNNotificationDismissActionIdentifier: // Notification was dismissed by user
completionHandler()
case UNNotificationDefaultActionIdentifier: // App was opened from notification
completionHandler()
default:
completionHandler()
}
}
UIApplication.shared.applicationIconBadgeNumber += 1