Flutter: FCM 푸쉬 알림

Notification눌른 다음 다른 화면으로 Push하려면?

https://firebase.google.com/docs/cloud-messaging

iOS Setup

  1. XCode에서 Targets — Runner — Signing & Capabilities에서 + 를 클릭하여 Push Notification을 추가합니다. Background Mode도 추가하여 Background fetch 와 Remote notification을 추가합니다.
XCode

Android Setup

<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="high_importance_channel" />

Initialize Firebase

flutter pub add firebase_messaging
flutter pub add firebase_core
flutter pub add flutter_local_notifications
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await FirebaseService.initializeFirebase();
runApp(const MyApp());
}

Get/Check Device Token

Future<String?> getDeviceToken() async => await FirebaseService.firebaseMessaging.getToken();

Receiving Notification

When App is in the Foreground — Android

@override
void init() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
FCMProvider.setContext(context);
});
}

When App is in the Background (Android) & When App is in Foreground/Background (iOS)

When App is Terminated

Backend

"apns: { 
"payload": {
"aps": {
"sound": default
}
}
}

--

--

Flutter & Node.js Full-Stack Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store