Mobile의 flutter push Notifircation 참고
const schedule = require('node-schedule');
const admin = require('firebase-admin');
var serviceAccount = require("{firebase 콘솔에서 받은 server용 json파일}");
var certPath = admin.credential.cert(serviceAccount)
admin.initializeApp({
credential : certPath
});
//알림 보내기 1분마다 동작하는 스케줄링 코드
schedule.scheduleJob(' */1 * * * *', function () {
//...
//원하는 로직.....
notificationHandler(when, token )
})
// 내 서버 예시로 자신의 알림 로직에 맞게 변경해야함
function notificationHandler(when, token){
//...
//원하는 로직.....
console.log("send")
sendPushNotification(token, "제목", "내용");
}
function sendPushNotification(target_token, title, body) {
//target_token은 푸시 메시지를 받을 디바이스의 토큰값입니다
let message = {
notification: {
title: title,
body: body,
},
data: {
route: 'main' // flutter 환경에서 알림 클릭시 라우팅 해주기 위한 데이터 없어도 됨
},
android:{
priority:"high",
notification: {
channelId: //firebase Channel ID(android_channel_id)
}
},
token: target_token,
apns: {
payload: {
aps: {// 얘네는 IOS 설정인데 웬만하면 유지하되 잘 찾아보고 설정하는 것을 추천한다.
badge: 2.0,
"apns-priority": 5,
sound: 'default'
},
},
},
}
admin.messaging().send(message)
.then(()=> {
console.log("success");
})
}
JavaScript
복사

.png&blockId=7628ec0c-1357-4c37-a1e9-32a282f6efaa)

.png&blockId=be06ed4d-0152-4f0f-b4b4-821bd1fb30d9)
.png&blockId=39a86e12-3cf4-40df-8d5e-9891c5adc274)



_%25E1%2584%2587%25E1%2585%25A9%25E1%2586%25A8%25E1%2584%2589%25E1%2585%25A1%25E1%2584%2587%25E1%2585%25A9%25E1%2586%25AB.png&blockId=891e6648-1148-4e7c-bfcd-0463dc71545c)

.png&blockId=5e737e69-4f36-437b-95e0-7db747173000)
.png&blockId=5294c22e-8cee-4109-963f-c8cfe8c852cf)