Firebase云消息(Flutter):订阅主题时出现错误消息



我的应用程序中包含了Firebase Messaging,当我尝试订阅主题时,会出现以下错误。

FLTFirebaseMessaging: An error occurred while calling method Messaging#subscribeToTopic, errorOrNil => {
NSLocalizedFailureReason = "Invalid registration response :'Error=INVALID_PARAMETERS'. It is missing 'token' field.";
}
flutter: subscription error: [firebase_messaging/unknown] An unknown error has occurred.

正如你所看到的,它只是简单地说";出现未知错误";,这对我没有太大帮助。

这是我的代码,它旨在获得推送通知的权限,然后获取令牌并订阅主题列表。。。

Future<void> requestMessagingPermission() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
NotificationSettings settings = await messaging.requestPermission(
alert: true,
announcement: false,
badge: true,
carPlay: false,
criticalAlert: false,
provisional: false,
sound: true,
);
print('User granted permission: ${settings.authorizationStatus}');
if (settings.authorizationStatus == AuthorizationStatus.authorized) {
print('User granted notifiactions permission');
messaging.getToken().then((token) async {
print('Messaging token: $token');
//configure notification topics
//gets a list of strings (topic names) from provider and loops through them to subscribe to them all
GlobalProvider provider = context.read<GlobalProvider>();
if (provider.notificationTopicsSet == false) {
//subscribe to topics
for (var topic in provider.notificationTopics) {
print('topic subscribing... $topic');
try {
await messaging.subscribeToTopic(topic).then((value) => print('topic subscribed: $topic'));
} catch (e) {
print('subscription error: $e');
}
}
}
});
}
}

对于正在循环和订阅的每个主题,我在控制台中都会遇到同样的错误。奇怪的是,推送通知以前是有效的,但现在似乎不起作用了。

我尝试将Flutter更新到最新版本(3.3.7(,我尝试将Firebase Core软件包(2.1.1(和Firebase消息传递软件包更新到最新版(14.0.4(,但我仍然收到错误。

来自pubspec.yaml:

firebase_core: ^2.1.1
firebase_messaging: ^14.0.4

缺少的token是什么?subscribeToTopic()函数似乎只接受主题名称字符串。我是不是错过了什么?

谢谢你,任何帮助都将不胜感激。

这最终只是iOS模拟器的一个问题。Android模拟器没有出现错误,推送通知在物理设备上运行良好。

相关内容

  • 没有找到相关文章

最新更新