我已经在我的应用程序中包含了Firebase消息,当我try 订阅主题时,我收到以下错误.
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');
}
}
}
});
}
}
我在控制台中收到的每个正在循环和订阅的主题都有相同的错误.奇怪的是,推送通知以前是有效的,但现在似乎不起作用了.
我已经try 将Ffltter更新到最新版本(3.3.7),我已经try 将Firebase核心包(2.1.1)和Firebase消息传递包更新到它们的最新版本(14.0.4),但我仍然收到错误.
From pubspec.yaml:个
firebase_core: ^2.1.1
firebase_messaging: ^14.0.4
这token
个遗失的是什么?subscribeToTopic()
函数似乎只接受主题名称字符串.我是不是遗漏了什么?
谢谢你,任何帮助都将不胜感激.