firebase_messaging: ^11.1.0
firebase_core: ^1.10.0
<uses-permission android:name="android.permission.INTERNET"/>
<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
apply plugin: 'com.google.gms.google-services'
dependencies {
implementation platform('com.google.firebase:firebase-bom:29.0.0')
implementation 'com.google.firebase:firebase-analytics'
}
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0'
classpath 'com.google.gms:google-services:4.3.10'
}
// Receive message when app is in background
Future<void> backgroundHandler(RemoteMessage message) async{
print("Handling a background message: ${message.messageId}");
}
Future main() async{
WidgetsFlutterBinding.ensureInitialized();
if (Platform.isAndroid) {
await AndroidInAppWebViewController.setWebContentsDebuggingEnabled(true);
}
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(backgroundHandler);
runApp(MyApp());
if (Platform.isIOS) {
Future.microtask(() async {
await FirebaseMessaging.instance
.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
).then((settings) {
print('User granted permission: ${settings.authorizationStatus}');
});
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
});
}
// gives you the message on which user taps and it opened the app from teminated state
FirebaseMessaging.instance.getInitialMessage().then((message){
print(message);
});
// forground
FirebaseMessaging.onMessage.listen((message) {
String title = '';
String body = '';
print(message);
if(message.notification != null) {
title = message.notification!.title!;
body = message.notification!.body!;
}
Get.snackbar(title, body,
snackPosition: SnackPosition.TOP,
backgroundColor: Colors.white,
duration: Duration(seconds: 3));
});
// When the app is in background but opened and user taps
FirebaseMessaging.onMessageOpenedApp.listen((message) {
print(message);
});
String? token = await FirebaseMessaging.instance.getToken();
print("token : ${token ?? 'token NULL!'}");
자세히 보면 그 위부터 에러 메시지가 있음
[!] CocoaPods could not find compatible versions for pod "firebase_messaging":
In Podfile:
firebase_messaging (from `.symlinks/plugins/firebase_messaging/ios`)
참조 :: https://github.com/FirebaseExtended/flutterfire/issues/4709
As mentioned in the changelog the minimum deployment target is now iOS 10.
Go to your Podfile and uncomment
# platform :ios, '9.0'
Then change the version to 10
platform :ios, '10.0'
>> 2가지를 고침 xcode 에서 deployment target을 iOS 10으로 고치고 아래와 같이 실행
1. flutter clean
2. pod update (flutter pub get을 하라는 메시지가 나오면 그것 하고 pod update하면 됨)