[英]Flutter FCM push notification not receiving on IOS with firebase_messaging: ^9.1.3
I have tried every solution on StackOverflow and GitHub but I am still not receiving notifications in IOS.我已经在 StackOverflow 和 GitHub 上尝试了所有解决方案,但我仍然没有在 IOS 中收到通知。 In android, it is working fine but in IOS, it is not.在 android 中,它工作正常,但在 IOS 中,它不是。 I am using the latest version of the firebase_messaging plugin ie ^9.1.3 with the new functions they have introduced.我正在使用最新版本的 firebase_messaging 插件,即 ^9.1.3 以及他们引入的新功能。 Can anyone help, please?有人可以帮忙吗? Below is the code I have used to get the notification data下面是我用来获取通知数据的代码
I am testing this in real IOS device with version 14.2 and I have also enabled the notifications in settings.我正在使用版本 14.2 的真实 IOS 设备中对此进行测试,并且我还在设置中启用了通知。
Future<void> _firebaseMessagingBackgroundHandler(
RemoteMessage message) async {
// If you're going to use other Firebase services in the background, such as Firestore,
// make sure you call `initializeApp` before using other Firebase services.
await Firebase.initializeApp();
print('Handling a background message ${message.messageId}');
}
void firebaseCloudMessaging_Listeners() {
if (Platform.isIOS) iOS_Permission();
_firebaseMessaging.getToken().then((token) {
print(token);
});
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print(message.notification.body);
RemoteNotification notification = message.notification;
AndroidNotification android = message.notification?.android;
if (notification != null && android != null) {}
});
FirebaseMessaging.onMessageOpenedApp.listen((RemoteMessage message) {
print('A new onMessageOpenedApp event was published!');
nextScreen(message, "onLaunch");
});
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}
// for IOS permision
void iOS_Permission() async {
NotificationSettings settings = await _firebaseMessaging.requestPermission(
announcement: true,
carPlay: true,
criticalAlert: true,
provisional: false,
sound: true,
badge: true,
alert: true);
}
// setting up the variables I need
FirebaseMessaging setUpFirebase(Function next, BuildContext context) {
_firebaseMessaging = FirebaseMessaging.instance;
firebaseCloudMessaging_Listeners();
this.context = context;
return _firebaseMessaging;
}
void deleteFirebaseInstance() {
_firebaseMessaging.deleteToken();
}
For iOS, you need对于 iOS,您需要
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.