在IOS上未接收到Flutter FCM推送通知,带有firebase_messaging:^9.1.3



我在StackOverflow和GitHub上尝试了所有解决方案,但在IOS中仍然没有收到通知。在安卓系统中,它工作得很好,但在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,您需要

  • 包括推送通知:https://developer.apple.com/account/resources/identifiers/bundleId
  • 在Xcode的Capability中添加推送通知
  • Firebase控制台上的Config.p8文件

相关内容

  • 没有找到相关文章

最新更新