0

Android 클라이언트 클라이언트 응용 프로그램관리 응용 프로그램에 Firebase를 사용하고 있습니다. 사용자가 클라이언트 응용 프로그램에 등록 할 때마다 Admin 응용 프로그램에 푸시 알림을 보내야합니다. Cloud Functions for Firebase을 사용하려고합니다. 나는 함수를 export했다. 그리고 firebase 콘솔에서도 볼 수있다.Google Cloud 기능 및 Google Firebase를 사용하여 푸시 알림

enter image description here

이 내 하는 index.js입니다 여기

const functions = require('firebase-functions'); 
const admin = require('firebase-admin'); 
admin.initializeApp(functions.config().firebase); 


exports.sendMessageToAdmin = functions.database.ref('/tokens/users/{userId}/{regToken}').onWrite(event => { 

    if (event.data.previous.exists()) { 
    return; 
    } 

    const userId = event.params.userId; 
    const regToken = event.params.regToken; 

    // Notification details. 
    const payload = { 
     notification: { 
     title: 'You have a new User.', 
     body: `${userId} is the id.`, 
     } 
    }; 
    return admin.messaging().sendToDevice(regToken, payload); 
}); 

내 데이터베이스 구조는 중포 기지에 있습니다 :

enter image description here

내가 푸시를 보낼 수있는 온라인 포털을 사용하는 경우 또는 테스트 목적으로 관리 앱에 푸시를 전송하는 FCM 일지라도 푸시. 그러나이 클라우드 기능은 푸시를 보내지 않습니다. 누군가 내가 뭘 잘못하고 있는지 안내 할 수 있습니까? 내가 다음에 기능을 변경하는 경우

편집

, 그것은 작동합니다. 하지만 여전히 위의 기능이 작동하지 않는 이유는 궁금합니다. 원래 코드에서

exports.sendMessageToAdmin = functions.database.ref('/tokens/users/{userId}').onWrite(event => { 


    if (event.data.previous.exists()) { 
    return; 
    } 

    const userId = event.params.userId; 
    var eventSnapshot = event.data; 
    const regToken = eventSnapshot.child("regToken").val(); 

    Notification details. 
    const payload = { 
     notification: { 
     title: 'You have a new User.', 
     body: `${userId} is the id.`, 
     } 
    }; 
    return admin.messaging().sendToDevice(regToken, payload); 
}); 
+0

성공 또는 오류 응답을 받으시겠습니까? –

+0

로그 문을 추가하고 Firebase 콘솔의 로그 창에서 출력을 찾으십시오 :'console.log ('userId :', userId, 'token :', regToken); ' –

+0

Firebase 로그 출력 내용은 무엇입니까? Firebase 콘솔의 'Functions -> Logs'에서 찾을 수 있습니다. –

답변

1

, 당신은이 :

const regToken = event.params.regToken; 

event.params.regToken

그것을 참조의 wildcard path segment의 값을 반환 regToken의 값을 반환하지 않습니다.

관련 문제