无法看到使用firebase发送的通知



我有一个移动设备正在使用FirebaseMessaging.instance.subscribeToTopic("newTopic")注册主题

我正在使用OAuth 2.0 Playground获取访问令牌。我发送了一个POST请求,如下所示,但在注册到该主题的设备上没有看到任何通知。CURL请求返回200 OK的状态代码。

curl -X POST -k -H 'Authorization: Bearer access_token_goes_here' -H 'Content-Type: application/json' -i 'https://fcm.googleapis.com/v1/projects/projectId/messages:send' --data '{
"message":{
"topic" : "newTopic",
"notification" : {
"body" : "This is a Firebase Cloud Messaging Topic Message!",
"title" : "FCM Message"
}
}
}

只是想知道我是否收到通知,我处理通知如下:

FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print('Got a message whilst in the foreground!');
print('Message data: ${message.data}');
if (message.notification != null) {
print('Message also contained a notification: ${message.notification}');
}
});
Initial notification configuration:
await Firebase.initializeApp();
FlutterLocalNotificationsPlugin flutterNotificationPlugin =
FlutterLocalNotificationsPlugin();
const AndroidNotificationChannel channel = AndroidNotificationChannel(
'channel ID',
'channel name',
playSound: true,
importance: Importance.max,
);
await flutterNotificationPlugin
.resolvePlatformSpecificImplementation<
AndroidFlutterLocalNotificationsPlugin>()
?.createNotificationChannel(channel);
var initializationSettingsAndroid =
const AndroidInitializationSettings('@mipmap/ic_launcher');
var initializationSettingsIOS = const DarwinInitializationSettings();
var initializationSettings = InitializationSettings(
android: initializationSettingsAndroid, iOS: initializationSettingsIOS);
await flutterNotificationPlugin.initialize(
initializationSettings,
);

//LocalNotification显示

FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
if (!kIsWeb) {
await FirebaseMessaging.instance
.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
RemoteNotification? notification = message.notification;
//AndroidNotification? android = message.notification?.android;
if (notification != null) {
log("On message: $notification");
log(message.data.toString());
if (Platform.isAndroid) {
FlutterLocalNotificationsPlugin().show(
0, notification.title, notification.body, notificationDetails);
}
}
});

相关内容

  • 没有找到相关文章

最新更新