FlutterとFirebaseMessagingを使用しています。例のようにFirebaseを設定します。firebaseMessaging.configure( onMessage: ... onLaunch: ... onResume: ... )
ただし、アプリが開いているときでもプッシュ通知が表示されます。
大まかに言えば、onMessageはonResumeのように機能するはずです。
これどうやってするの?
onMessage: (Map<String, dynamic> message) async {
showNotification(message);
print('on message $message');
}
showNotification(Map<String, dynamic> msg) async {
var android = new AndroidNotificationDetails(
'your channel id',//channel id
"your channel name",//channel name
"your channel description",//channel desc todo set all this right
icon: 'mipmap/launcher_icon'//add your icon here
);
var iOS = new IOSNotificationDetails();
var platform = new NotificationDetails(android, iOS);
await flutterLocalNotificationsPlugin
.show(0, msg['notification']['title'], msg['notification']['body'], platform);
}
flutter_local_notifications:^ 1.2.2を使用して、ローカル通知のフォアグラウンドを表示しました。
さらに、IOSを実装している場合は、通知の許可を求めることを忘れないでください。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加