3

This is what my log looks like when my push notification gets called on중포 기지 클라우드 메시징 푸시 알림되지는 장치

나는 현재 아이폰에 대한 사용자 설정에 사용자에 대해 설정 푸시 알림을 만드는 작업입니다로 전송된다. 현재 Firebase를 사용하고 있으므로 당연히 Firebase Cloud Messaging을 사용하여이 작업을 완료했습니다. 이것은 내 Firebase에 배포 할 기능의 설정입니다. 여기에 잘못된 내용이있어 알림이 장치로 전송되지 않습니다. 어떤 도움을 주셔서 감사 드리며 더 이상 필요한 정보가 있으면 제공해 드릴 수 있습니다.

const functions = require('firebase-functions'); 

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

// Listens for new messages added to messages/:pushId 
exports.pushNotification =  functions.database.ref('/messages/{pushId}').onWrite(event => { 

console.log('Push notification event triggered'); 

// Grab the current value of what was written to the Realtime Database. 
var valueObject = event.data.val(); 
console.log(valueObject) 

if(valueObject.photoUrl != null) { 
    valueObject.photoUrl= "Sent you a photo!"; 
} 

// Create a notification 
const payload = { 
    notification: { 
     title:valueObject.toId, 
     body: valueObject.text || valueObject.photoUrl, 
     sound: "default" 
    }, 
}; 

//Create an options object that contains the time to live for the notification and the priority 
const options = { 
    priority: "high", 
    timeToLive: 60 * 60 * 24 
}; 
return admin.messaging().sendToTopic("pushNotifications", payload, options); 
if(!data.changed()){ 

}); 

exports.pushNotification = functions.database.ref('/messages/{pushId}').onWrite(event => { 
const data = event.data; 
console.log('Push notification event triggered'); 
return; 
} 



}); 
+0

firebase cloud messaging 섹션에 p12를 업로드 했습니까? –

+0

안녕하세요, 답장을 보내 주셔서 감사합니다! 나는 p12가 뭔지 잘 모르겠다. @JigneshMayani – oneQuestionAsker

+0

응답에 오류가 있습니까? –

답변

-1

보내기 당신이 푸시 알림 을이 게시물 요청 메서드 본문 여기

{ "registration_ids" : [Send Array of Device Token], 
    "data" : 
    { 
    "image_url" : "send your image here" 
    "message" : "Send your message here" }, 
"notification" : 
    { 
    "title" : "APP Name", 
    "sound" : "default", 
    "priority" : "high" 
    } 
} 

가 있습니다 보낼 당신의 모든 기기 토큰의 배열을 게시 할 registration_ids 필드에 포스트 매개 변수에이 jsone 요청 후 URL

https://fcm.googleapis.com/fcm/send

및 전송 key="Your Authorization key" HttpHeader 저런 클라우드 메시징 여기를 기본 설정 양식에 대한 LD

테이크 참조는

https://firebase.google.com/docs/cloud-messaging/ios/client

+0

OP의 경우, 그는 분명히 Firebase Admin 모듈을 사용하여 요청을합니다 (admin.messaging()을 통해). 여기에 제안하는대로 HTTP 요청을하지 않을 것입니다. 참조한 링크는 Swift와 Objective C 만 참조하고 OP 질문은 JS 라이브러리와 관련됩니다. 그 이유만으로도 나는 대답을 downvoting 해요. – AlxVallejo

0

나는 당신이 두 번 같은 기능을 노출하는 것으로 나타났습니다. 그것은 또한 문제입니다. 또한 당신이 처리하고 오류를 확인할 수 있도록 admin.messaging을 약속하는 것이 좋습니다.

let topic = "pushNotifications"; 
admin.messaging().sendToTopic(topic, payload, options) 
     .then(function(response) { 

      console.log("Successfully sent message:", response); 
      console.log("Topic: " + topic); 
      res.status(200).send("success"); 
     }) 
     .catch(function(error) { 
      console.log("Error sending message:", error); 
      res.status(500).send("failure"); 
     }); 
관련 문제