저는 여러분과 같았으며 "서버에서 해보기"이외의 다른 대답을 볼 수 없었습니다. 여기
내 방식 :
1) 당신이 응용 프로그램을 실행하면 중포 기지 실시간 데이터베이스로 제로 (변수가 당신이 원하는대로 호출 할 수 있습니다) 배지를 설정해야합니다. 게다가 여기에 설정 application.applicationIconBadgeNumber = 0 내가 AppDelegate에 그것을 할 방법은 다음과 같습니다
func applicationDidBecomeActive(_ application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
application.applicationIconBadgeNumber = 0
// Reset badge number to zero
let userID = Auth.auth().currentUser?.uid
let dbRef = Database.database().reference()
dbRef.child("Users Info").child(userID!).updateChildValues(["badge":"0"], withCompletionBlock: { (err, ref) in
if err != nil {
print(err!)
return
}
})
}
2) 함수가 트리거하는 index.js로 이동합니다.
...
return admin.database().ref('/Users Info/' + owner).once('value', snapshot => {
var ownerValue = snapshot.val();
var badgeNumber = parseInt(ownerValue.badge) + 1;
// Notification details.
const payload = {
notification: {
title: 'You have a new request!',
body: `A new request from ${downedBy.name}.`,
badge:`${badgeNumber}`,
sound: 'default',
}
};
...
...
// Upload the new value of badge into Firebase to keep track of the number
return admin.database().ref('/Users Info/' + owner).update({badge:badgeNumber});
...
})