CRIZEL
HOME
FOOD
GS
BOARD
로그인
홈
FOOD
GS
전체메뉴
▲
카테고리1
카테고리1 선택
프로그래밍
카테고리2
카테고리2 선택
AI
CSS
DB
Git
JAVA
JAVASCRIPT
MCP
mysql
NESTJS
NEXTJS
REMIX
도커
리액트
리액트 네이티브
미들웨어
브라우저
서버
스벨트킷
스프링
스프링부트
오라클
자바
자바스크립트
플러터
제목
작성자
1. 패키지 설치 npm install --save @react-native-firebase/app @react-native-firebase/messaging npm install react-native-push-notification 2. android/build.gradle 설정 buildscript { dependencies { classpath 'com.google.gms:google-services:4.3.15' } } 3. android/app/build.gradle apply plugin: 'com.google.gms.google-services' dependencies { implementation platform('com.google.firebase:firebase-bom:33.2.0') implementation 'com.google.firebase:firebase-messaging' } 4. google-services.json → android/app/ 경로로 복사 5. 권한설정 import messaging from '@react-native-firebase/messaging'; async function requestUserPermission() { const authStatus = await messaging().requestPermission(); const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL; if (enabled) { console.log('Authorization status:', authStatus); } } 6. 토큰 가져오기 const fcmToken = await messaging().getToken(); console.log('FCM Token:', fcmToken); 7. 알림 설정 import PushNotification from 'react-native-push-notification'; // 포그라운드 messaging().onMessage(async remoteMessage => { console.log('Foreground:', remoteMessage); }); // 백그라운드 messaging().setBackgroundMessageHandler(async remoteMessage => { PushNotification.localNotification({ channelId: "default-channel-id", title: remoteMessage.data.title || "새 알림", message: remoteMessage.data.body || "내용 없음", }); }); // 알림 열었을 때 messaging().onNotificationOpenedApp(remoteMessage => { console.log('remoteMessage : ', remoteMessage); }); // 앱 완전 종료 후 열었을 때 messaging().getInitialNotification().then(remoteMessage => { if (remoteMessage) { PushNotification.localNotification({ channelId: "default-channel-id", title: remoteMessage.data.title || "새 알림", message: remoteMessage.data.body || "내용 없음", }); } });
저장
뒤로가기