알림

부가설명
- 푸시알림 전송 모듈 제작 후 백엔드에게 전달 - 모바일 푸시알림 웹뷰 연동 구현
Tags
RN
backend
module
PushNoti

1) 포그라운드 푸시알림 처리

notion image
과제, 포럼 알림 개수 별도관리
notion image
탭 클릭 시 알림개수 초기화
notion image
탭 클릭 시 알림개수 초기화
 

2) 백그라운드 푸시알림 처리

과제 알림

  • 푸시 알림 클릭 시, 해당 과제로 이동

포럼 알림

  • 푸시 알림 클릭 시, 해당 포럼으로 이동

과제 푸시알림 연동

notion image
 

포럼 푸시알림 연동

notion image

3) 알림 형식 정의

과제 알림 형식

notification: { title: "새로운 과제가 등록되었습니다!", body: "Title: React 조사", }, data: { assignId, },

포럼 알림 형식

notification: { title: "새로운 댓글이 등록됐습니다!", body: "Title: React 조사", }, data: { courseId, forumId, },
 

node.js 메세지 송신 테스트 소스코드

const { response } = require("express"); const express = require("express"); const router = express.Router(); var admin = require("firebase-admin"); var serviceAccount = require("/Users/night-ohl/Desktop/develop/nodeEnv/opstech-fcm-90mobile.json"); admin.initializeApp({ credential: admin.credential.cert(serviceAccount), }); /** * 포럼 : http://ip/student/courseforum/post/${courseId}/${forumId} * 과제 : http://ip/student/assignment/${assignId} */ router.get("/personal", (req, res, next) => { const registrationToken = [ "---------", // android "---------", // ios ]; const assignId = (3).toString(); const courseId = (2).toString(); const forumId = (5).toString(); const payload = { newAssignment: { notification: { title: "새로운 과제가 등록되었습니다!", body: "Title: React 조사", }, data: { assignId, }, }, newFeedback: { notification: { title: "새로운 피드백이 등록됐습니다!", body: "Title: React 조사", }, data: { assignId, }, }, newComment: { notification: { title: "새로운 댓글이 등록됐습니다!", body: "Title: React 조사", }, data: { courseId, forumId, }, }, newResolve: { notification: { title: "답변이 채택되었습니다!", body: "Title: React 조사", }, data: { courseId, forumId, }, }, }; const notshow_payload = { data: { hi: "hello", }, }; admin .messaging() .sendToDevice(registrationToken, payload.newComment, { // Required for background/quit data-only messages on iOS contentAvailable: true, // Required for background/quit data-only messages on Android priority: "high", }) .then((response) => { console.log("Successfully sent message:", response); }) .catch((error) => { console.log("Error sending message:", error); }); res.send("Push-Noti 테스트 완료"); }); module.exports = router;