sitelink1 | https://www.omnibuscode.com/board/board_mobile/58328 |
---|---|
sitelink2 | https://www.omnibuscode.com/kanban/?cont...5#comments |
sitelink3 |
그동안 관련 기술과 레퍼런스 문서들을 찾아 실습을 진행하는데
완료 시일이 자꾸만 늘어져서 진행했던 학습을 일부 반복하는 시행착오가 있어 이를 막기 위해 기록을 해둔다.
하기 링크들의 문서에서는 진행상의 해당 파트에(client 와 server 의 매커니즘) 대해서만 참고해야 한다.
FCM 의 API 들이 버전업을 하면서 개인 블로그의 포스팅에서 작성된 코드들이 deprecated 되거나 changed 된 것들이 많다.
ex> Deprecated useVapidKey and useServiceWorker. Use getToken to set these values instead.
0. prologue
0.0. https://galid1.tistory.com/740#:~:text=Push%20Notification%20%EB%8F%99%EC%9E%91
0.1. 용어 정의
- Notification Server
FCM, GCM, APNs 와 같이, mobile 기기의 client app에 push notification 을 전송하는 서버
- Client App
사용자의 mobile기기에 설치된 app (service worker)
- Provider
push notification 을 생성하여 notification server 로 발송하는 서버
0.2. notification 전송 과정
- Client App을 Notification Server에 등록
- Client App을 켜면 각각의 Client App을 구분하는 Token 을 Notification Server에서 발급
- Client App에서 이 Token 을 Provider로 전송
- Provider는 Token 을 저장
- Client App에 알림을 전송할 필요가 있을때, Token 값과 함께 Notification Server에 요청
- Client App에서 Push 알림을 수신
1. service worker 구현 및 등록 (client - web javascript)
1.1. service worker 의 event 구현
- service-worker.js 에 oninstall, onactivate, onfetch, onpush, onotificationclick 등의 이벤트 함수를 정의
1.2. service worker 의 register(등록)
1) jiniebox.js 에서 playServiceWorker() 함수 참고
2) 레퍼런스
- https://firebase.google.com/docs/web/alt-setup?hl=ko
- https://naitas.tistory.com/entry/%EC%9B%B9%ED%91%B8%EC%8B%9C-WEB-PUSH-FCM
2. fcm 설정 및 service 구현 (server - java)
2.1. Google Firebase Messaging 프로젝트 생성
- https://blog.naver.com/jinwoo6612/222479649921
2.2. FCM 을 이용하여 메세지를 전송하는 방식 (선택하여 서버 서비스를 구현)
2.2.1. FCM용 Firebase Admin SDK
Admin SDK는 권한 있는 환경에서 Firebase와 상호작용 할 수 있게 해주는 서버 라이브러리 세트
1) 적용 및 구현 절차
- SDK 초기화
2) 레퍼런스
- https://firebase.google.com/docs/reference/admin?authuser=0&hl=ko
- https://firebase.google.com/docs/admin/setup?hl=ko&authuser=0
- https://blog.naver.com/saka/222626724097
- https://blog.naver.com/steve6133/223155243517
- https://herojoon-dev.tistory.com/23
2.2.2. HTTP V1 API (REST)
플랫폼간 메시징 솔루션을 제공하는 FCM 전송 REST API
1) 레퍼런스
- https://firebase.google.com/docs/reference/fcm/rest?hl=ko
- https://firebase.google.com/docs/reference/fcm/rest/v1/projects.messages?authuser=0&hl=ko
- https://galid1.tistory.com/740
- https://blog.naver.com/aozp73/223061144172
1. Firebase 에서 서비스 계정의 새로운 비공개 키 파일을 생성
> 프로젝트 > 프로젝트 설정 > 서비스 계정 > 새 비공개 키 생성 > [프로젝트 ID]-firebase-adminsdk-...json 파일 다운로드
> reference : https://firebase.google.com/docs/admin/setup?authuser=0&hl=ko#initialize_the_sdk_in_non-google_environments