【发布时间】:2021-07-24 17:52:02
【问题描述】:
我已经尝试了 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();
}
【问题讨论】:
-
我已经在 Xcode 中启用了推送通知、后台模式(带有后台获取和远程通知)
-
为了确定……您是在尝试在真实的 IOS 设备上接收通知,还是在使用 IOS 模拟器运行?
-
进入你的iOS设备,设置,找到你的应用,打开它的设置,检查你的应用是否启用了通知设置。
-
嘿,是的,我使用的是 IOS 14.2 版本的真实设备,并且启用了通知。
标签: ios swift firebase flutter firebase-cloud-messaging