[英]Not Receive FCM Push notification in IOS.While app in background or terminate.I m use FirebaseMessaging 6.0.9 Pub
[英]How I can receive FCM notification only when app is terminated and doesn't receive it if app is working in background
我在我的 flutter 应用程序中处理 FCM,如果我的应用程序终止,我只想收到一个预定的通知,如果应用程序现在在后台运行,我不想收到它。
这是我的代码,当我测试时,如果我的应用程序处于后台或已终止,我会收到此通知。
Future<void> background_handler(RemoteMessage message) async {
await Firebase.initializeApp();
}
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: FirebaseOptions(apiKey:
"apikey", appId: "appid", messagingSenderId: "senderid", projectId: "projid"));
//handle msg in terminate case
RemoteMessage? message = await FirebaseMessaging.instance.getInitialMessage();
if(message != null){
PushNotification notification = new PushNotification(title:
message.notification?.title?? "Title",
body: message.notification?.body?? "Body", dataTitle: message.data["title"],
dataBody: message.data["body"] );
}
FirebaseMessaging.onBackgroundMessage(background_handler);
runApp(const MyApp());
}
我如何更改此代码以使应用程序仅在终止时收到此通知,或者无法将后台和终止案例分开?
我不认为这是可能的,因为onBackgroundMessage
在应用程序处于后台和终止时处理消息 state。此外,Flutter 只能检测应用程序是否在后台,但不能检测它何时终止。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.