Flutter 푸시 알림 가이드
작성일: 2026-04-06 Last Updated: 2026-04-06 대상: Flutter Mobile App (iOS / Android) 공통 참조:
../common/api-integration.md(API 연동 패턴)
목차
- 푸시 알림 아키텍처
- FCM 설정 (Firebase Cloud Messaging)
- APNs 설정 (Apple Push Notification service)
- Flutter 클라이언트 구현
- 로컬 알림 (flutter_local_notifications)
- 알림 채널 관리 (Android)
- 딥 링크 연동
- 백그라운드 메시지 처리
- 서버 측 구현 (Laravel)
- 토픽 구독 및 사용자 타겟팅
- 알림 권한 요 청 UX
- 체크리스트
1. 푸시 알림 아키텍처
전체 흐름
Laravel 서버
│
├── Firebase Admin SDK ──→ FCM 서버 ──→ Android 디바이스
│ │
│ FCM 서버 ──→ APNs ──→ iOS 디바이스
│
└── 토큰 DB 저장 (device_tokens 테이블)
↑
Flutter 앱 (FCM 토큰 등록)
메시지 유형
| 유형 | 설명 | 앱 포그라운드 | 앱 백그라운드 | 앱 종료 |
|---|---|---|---|---|
| Notification | 시스템 트레이 알림 | 자동 표시 X (핸들러) | 자동 표시 O | 자동 표시 O |
| Data | 커스텀 데이터 | 핸들러 호출 | 핸들러 호출 | 핸들러 호출 |
| Notification + Data | 혼합 | 핸들러 호출 | 트레이 표시 + 탭 시 데이터 | 트레이 표시 + 탭 시 데이터 |
권장: Data 전용 메시지 +
flutter_local_notifications로 직접 표시 (모든 상태에서 제어 가능).
2. FCM 설정 (Firebase Cloud Messaging)
Firebase 프로젝트 설정
| 단계 | 작업 |
|---|---|
| 1 | Firebase Console (https://console.firebase.google.com) 프로젝트 생성 |
| 2 | Android 앱 추가: 패키지명 입력 -> google-services.json 다운로드 |
| 3 | iOS 앱 추가: Bundle ID 입력 -> GoogleService-Info.plist 다운로드 |
| 4 | APNs 키 업로드 (iOS 푸시용) |
Flutter 패키지 설정
# pubspec.yaml
dependencies:
firebase_core: ^3.0.0
firebase_messaging: ^15.0.0
flutter_local_notifications: ^18.0.0
Android 설정
// android/build.gradle
buildscript {
dependencies {
classpath 'com.google.gms:google-services:4.4.2'
}
}
// android/app/build.gradle
apply plugin: 'com.google.gms.google-services'
android/app/
├── google-services.json # Firebase 설정 (Git 제외 권장)
└── src/main/AndroidManifest.xml
google-services.json Flavor별 관리
android/app/src/
├── dev/google-services.json # Dev Firebase 프로젝트
├── staging/google-services.json # Staging Firebase 프로젝트
└── prod/google-services.json # Prod Firebase 프로젝트
3. APNs 설정 (Apple Push Notification service)
APNs 인증 키 (권장)
| 단계 | 작업 |
|---|---|
| 1 | Apple Developer > Keys > 새 키 생성 |
| 2 | "Apple Push Notifications service (APNs)" 체크 |
| 3 | .p8 키 파일 다운로드 (1회만 가능, 안전 보관) |
| 4 | Firebase Console > Project Settings > Cloud Messaging |
| 5 | iOS 앱 > APNs Authentication Key 업로드 |
APNs 키 vs 인증서
| 항목 | APNs Key (.p8) | APNs Certificate (.p12) |
|---|---|---|
| 유효기간 | 무기한 | 1년 (갱신 필요) |
| 환경 | Sandbox + Production 공용 | 환경별 별도 |
| 관리 | 간편 | 복잡 |
| 권장 | O | X |
iOS Capability 설정
Xcode에서:
- Signing & Capabilities > + Capability
- Push Notifications 추가
- Background Modes 추가 > Remote notifications 체크
ios/Runner/Runner.entitlements:
aps-environment: development (또는 production)