当Flutter应用在IOS设备上运行时,不会收到FCM推送通知。一旦应用进入后台或最小化,推送通知就会正常工作。
我使用了firebase_messaging和flutter_local_notifications插件。
initialize() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
SharedPreferences sharedPreferences = await
SharedPreferences.getInstance();
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted permission');
} else if (settings.authorizationStatus ==
AuthorizationStatus.provisional) {
print('User granted provisional permission');
} else {
print('User declined or has not accepted permission');
}
messaging.getToken().then((token) {
print("FCM TOKEN:- $token");
sharedPreferences.setString("fcmToken", token.toString());
});
FirebaseMessaging.onMessage.listen((RemoteMessage event) {
print("message received");
print(event.notification!.body);
flutterLocalNotificationsPlugin.show(
1,
event.notification!.title.toString(),
event.notification!.body.toString(),
NotificationDetails(
android: AndroidNotificationDetails(
channel.id,
channel.name,
color: Colors.amber,
playSound: true,
icon: '@mipmap/ic_launcher',
),
));
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
print('Message clicked!');
});
}
字符串
有人能帮帮我吗?
1条答案
按热度按时间k4aesqcs1#
当你在onMessage中监听通知时,你只添加了android规范。请同时添加IOS规范。
字符串