![](/img/trans.png)
[英]How to debug iOS not receiving push notifications (Flutter using firebase_messaging)?
[英]Flutter FCM push notification not receiving on IOS with firebase_messaging: ^9.1.3
我已經在 StackOverflow 和 GitHub 上嘗試了所有解決方案,但我仍然沒有在 IOS 中收到通知。 在 android 中,它工作正常,但在 IOS 中,它不是。 我正在使用最新版本的 firebase_messaging 插件,即 ^9.1.3 以及他們引入的新功能。 有人可以幫忙嗎? 下面是我用來獲取通知數據的代碼
我正在使用版本 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();
}
對於 iOS,您需要
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.