npm install @react-native-firebase/app @react-native-firebase/messaging
설치 후, iOS를 개발하는 경우에는 pod install 필수입니다.
cd ios
pod install
cd ..
※ Android만 작업할 경우 pod install은 필요 없습니다.
google-services.json 파일 다운로드android/app/ 폴더에 복사
buildscript {
dependencies {
// ... 원래 코드
classpath("com.google.gms:google-services:4.4.2") // 추가
}
}
apply plugin: 'com.google.gms.google-services'
이 설정이 있어야 google-services.json에 등록된 Firebase 정보를 앱이 읽을 수 있습니다.
PermissionsAndroid를 사용해 POST_NOTIFICATIONS 권한을 요청해야 합니다.<uses-permission android:name="android.permission.POST_NOTIFICATIONS" />

use_frameworks! :linkage => :static # 추가
use_modular_headers! # 추가
platform :ios, min_ios_version_supported
prepare_react_native_project!
Firebase와 React Native를 함께 사용할 때 발생할 수 있는 CocoaPods 충돌을 방지하기 위한 설정입니다.
use_frameworks! :linkage => :static
→ CocoaPods에서 라이브러리를 정적(static) 프레임워크로 연결하여 빌드 오류와 중복 링크 충돌을 예방합니다.
특히 React Native Firebase, Google 라이브러리와 같이 동적 프레임워크에서 문제를 일으킬 수 있는 경우 유용합니다.
use_modular_headers!
→ Firebase와 일부 서드파티 라이브러리에서 요구하는 모듈형 헤더 방식으로 pod를 불러옵니다.
충돌을 줄이고 호환성을 높이기 위해 사용합니다.
cd ios && pod install
ios/프로젝트이름/Info.plist에 아래 내용 추가
<key>UIBackgroundModes</key>
<array>
<string>remote-notification</string>
</array>
<key>NSPushNotificationUsageDescription</key>
<string>앱이 알림을 보내기 위해 권한이 필요합니다.</string>
이 설정은 앱이 백그라운드에서도 푸시 알림을 받을 수 있게 하고, 사용자에게 알림 권한을 요청하는 메시지를 설정합니다.
@react-native-firebase/messaging 또는 react-native-push-notification 등에서 권한 요청 API를 호출해야 합니다.
import messaging from '@react-native-firebase/messaging';
await messaging().requestPermission();
App.tsx 또는 앱 초기화 파일에 다음과 같이 작성합니다:
import React, { useEffect } from 'react';
import { View, Text, Platform, PermissionsAndroid } from 'react-native';
import { getApp } from '@react-native-firebase/app';
import messaging, {
getMessaging,
requestPermission,
AuthorizationStatus,
} from '@react-native-firebase/messaging';
const App = () => {
const requestUserPermission = async () => {
const app = getApp();
const messagingInstance = getMessaging(app);
if (Platform.OS === 'android') {
if (PermissionsAndroid && Platform.Version >= 33) {
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
);
if (granted !== PermissionsAndroid.RESULTS.GRANTED) {
console.log('🔴 Android 알림 권한 거부됨');
return false;
}
console.log('🟢 Android 알림 권한 허용됨');
return true;
}
return true;
} else {
const authStatus = await requestPermission(messagingInstance);
const enabled =
authStatus === AuthorizationStatus.AUTHORIZED ||
authStatus === AuthorizationStatus.PROVISIONAL;
console.log('🟢 iOS 권한 상태:', authStatus);
return enabled;
}
};
const getFcmToken = async () => {
const app = getApp();
const messagingInstance = getMessaging(app);
const token = await messagingInstance.getToken();
if (token) {
console.log('🔥 FCM Token:', token);
} else {
console.log('❗ 토큰 발급 실패');
}
};
useEffect(() => {
const init = async () => {
const hasPermission = await requestUserPermission();
if (hasPermission) {
await getFcmToken();
}
};
init();
// 토큰 갱신 감지
const unsubscribe = messaging().onTokenRefresh(token => {
console.log('🔁 FCM 토큰 갱신:', token);
});
return unsubscribe;
}, []);
return (
<View>
<Text>FCM 테스트 중</Text>
</View>
);
};
export default App;
| 항목 | 설명 |
|---|---|
| 실기기 테스트 | 에뮬레이터는 푸시 수신이 불안정함 (Android 실기기 권장) |
| Android 13+ | POST_NOTIFICATIONS 권한 반드시 요청해야 수신됨 |
| google-services.json 위치 | android/app/에 정확히 위치해야 인식됨 |
| iOS는 xcworkspace 사용 | .xcworkspace로 Xcode 열기 |
| 알림 권한 상태 확인 | 앱 설치 후 기기 설정 > 알림 허용 확인 |
Firebase 콘솔 → Cloud Messaging → 알림 전송 → 테스트 전송
테스트 대상 기기 FCM 토큰 입력 필요
| 앱 상태 | 동작 여부 확인 항목 |
|---|---|
| Foreground (앱 실행 중) | 커스텀 알림 UI 출력 필요 (기본 알림 미표시) |
| Background (백그라운드 실행 중) | 시스템 알림 정상 수신 여부 |
| Terminated (앱 완전 종료 상태) | 앱 실행 + 알림 처리 로직 정상 동작 여부 |
iOS는 APNs 인증 설정이 없으면 FCM 푸시가 작동하지 않습니다.