2017-09-20 8 views
0

이 질문은 중복 될 수 있지만 다시 물어보고 싶은데, 아마도 어떤 사람은 그것을 해결하는 방법을 알고있을 것입니다. 우리가 알다시피 응용 프로그램이 background에 원격 통지를받은 잎파리가Firebase에 배지 번호를 축적하는 방법은 무엇입니까?

, 우리는 badge number 1은 앱 아이콘을 표시합니다, Firebase으로 badge 푸시 전에 알림을 설정할 수 있습니다.

그런 다음 firebase에서 배지 값을 3으로 설정하고 메시지를 누릅니다. 아이콘의 배지 번호가 3이 아닌 4 (1 + 3)로 표시됩니다. 즉, 앱이 백그라운드 모드에 있고 2 개의 다른 메시지를받는 경우 배지 번호가 누적되어야합니다.

Firebase에서 어떤 방법을 사용할 수 있습니까? 어떤 점에 감사드립니다.

답변

1

당신이 맞습니다,이 질문은 여러 번 전에 질문되었습니다. Firebase Push Notification으로 만 할 수있는 일은 badge count을 앱에 표시되도록 설정하는 것입니다. 다시 말해, 수 없으며 배지 카운트를 유지하거나 유지할 수 없습니다.

앱에 배지의 현재 개수를 저장하려면 서버가 필요합니다.

silent push notification을 사용할 수도 있습니다. 여기에 애플의 문서 : 자동 알림이 사용자의 장치에 전달되는 https://developer.apple.com/library/content/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CreatingtheNotificationPayload.html

, 아이폰 OS는 백그라운드에서 응용 프로그램을 깨어나서 실행하는 데 30 초 그것을 제공합니다. iOS에서 시스템은 응용 프로그램 : didReceiveRemoteNotification : fetchCompletionHandler : 앱 대리인의 메소드를 호출하여 자동 알림을 전달합니다.

0

저는 여러분과 같았으며 "서버에서 해보기"이외의 다른 대답을 볼 수 없었습니다. 여기

내 방식 :

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}); 
    ... 
    })