在WWDC 2013的"多任务新功能"演示中,有一个关于静音推送通知的部分.看起来很简单.根据演示文稿,如果您将APS有效负载仅发送到内容可用设置为1,则不会通知用户该通知.
// A. This doesn't work
{
aps: {
content-available: 1
}
}
Run Code Online (Sandbox Code Playgroud)
我的测试显示,这不起作用,因为没有收到推送.但是,如果我包含声音属性但排除了alert属性,它就会起作用(虽然不再是静音).
// B. This works
{
aps: {
content-available: 1,
sound: "default"
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我更改声音属性以播放静音,我可以模仿静音.
// C. This works too.
{
aps: {
content-available: 1,
sound: "silence.wav"
}
}
Run Code Online (Sandbox Code Playgroud)
有人知道吗:
提前致谢.
编辑更多信息
对于A,应用程序的状态无关紧要.从未收到通知.
看起来B和C只有在将属性和值括在引号中时才有效,如下所示.
{"aps":{"content-available": 1, "sound":"silent.wav"}}
Run Code Online (Sandbox Code Playgroud)
并且通知到达应用程序:didReceiveRemoteNotification:fetchCompletionHandler:无论状态如何.
我正在尝试将从我的服务器发送到FCM的Firebase Cloud Messaging iOS警报显示在我的iOS设备上.
如果我从FCM控制台发送消息:
https://console.firebase.google.com/project/ your-awesome-project/notification
和FCM示例应用程序:
https://github.com/firebase/quickstart-ios
关闭或在后台,警报显示美妙,
如果它在前台我在iOS控制台中看到这个:
{
aps = {
alert = "HEY YO";
};
"gcm.message_id" = "0:123456789_blah_blah";
"gcm.n.e" = 1;
"google.c.a.c_id" = 123XXXXXXXX789;
"google.c.a.e" = 1;
"google.c.a.ts" = 123XXX789;
"google.c.a.udt" = 0;
}
Run Code Online (Sandbox Code Playgroud)
......但如果我试试这个:
curl -X POST
--header "Authorization: key=<server key>"
--header "Content-Type: application/json"
https://fcm.googleapis.com/fcm/send
-d "{\"to\":\"<device registration id>\",\"notification\":{\"body\": \"HEY YO\"}}"
Run Code Online (Sandbox Code Playgroud)
...无论FCM示例应用程序是在前台,后台还是完全关闭,它都不会显示为警报.
然而它确实出现在iOS控制台中,但参数较少:
{
aps = {
alert = "HEY YO";
};
"gcm.message_id" = "0:123456789_blah_blah";
}
Run Code Online (Sandbox Code Playgroud)
是否可以使用curl触发在我的iOS设备上显示为警报的Firebase云消息通知?
答案 [感谢亚瑟!] :
只需添加: \"priority\":\"high\"
像这样: …
curl apple-push-notifications ios google-cloud-messaging firebase-cloud-messaging
我正在尝试在我的 Flutter 应用程序中使用 Firebase Cloud Messaging 实现推送通知服务。这就是 FCM 文档所说的我们应该根据应用程序的当前状态(前台、后台或终止)处理通知的方式:
Foreground:我们有一个onMessage可以监听的流,但 FCM在前台状态时不会显示任何通知,因此我们必须使用FlutterLocalNotificationsPlugin它,这是我的实现:
FirebaseMessaging.onMessage.listen((RemoteMessage remoteMessage) {
// calling flutter local notifications plugin for showing local notification
scheduleNotification(remoteMessage);
});
Run Code Online (Sandbox Code Playgroud)
在scheduleNotification方法中我调用该FlutterLocalNotificationsPlugin().show()方法,到目前为止一切都按预期工作。
问题从这里开始:
后台,终止:Firebase 在此状态下自动显示通知,并且它有一个onBackgroundMessage。方法,我们可以向该方法传递一个在FCM 显示通知后运行的BackgroundMessageHandler 。这是我的后台处理程序的实现:
Future<void> backgroundMessageHandler(
RemoteMessage remoteMessage) async {
RemoteNotification? remoteNotification = remoteMessage.notification;
if (remoteNotification != null) {
FlutterLocalNotificationsPlugin().show(
remoteMessage.messageId.hashCode,
remoteNotification.title,
remoteNotification.body,
NotificationDetails(
android: AndroidNotificationDetails(
_androidNotificationChannel.id,
_androidNotificationChannel.name,
_androidNotificationChannel.description,
icon: 'launch_background',
importance: …Run Code Online (Sandbox Code Playgroud) mobile push-notification firebase flutter firebase-cloud-messaging
因此,在向Android设备发送通知时,您可以指定标签属性:
"notification": {
"title": title,
"body": message,
"sound": sound,
"tag": "STRING_TO_GROUP_NOTIFICATIONS_BY"
}
Run Code Online (Sandbox Code Playgroud)
这会将具有相同标签的通知分组在一起,以便在有大量通知时不会给用户带来混乱,而只会显示最新的通知。
这对于说说聊天应用程序非常有用,它具有多个接收大量消息的频道,因此您可以按频道分组并最大程度地减少用户通知中的噪音。
安薇
iOS有什么方法可以做到这一点吗?
android ios firebase google-cloud-messaging firebase-cloud-messaging
我正在开发一个带有 FCM 通知的 Android 应用程序。当应用程序在后台或前台时,我都能正确收到通知;它会发出声音并振动,单击通知会启动应用程序。一切都恰到好处。但是,当设备锁定且显示屏关闭时,设备会在收到通知时振动并发出声音。但它没有唤醒(屏幕没有打开)。只有在按下按键后,设备才会唤醒,即使在锁定屏幕中我也可以看到通知。
我有两个问题,
如何打开显示器?
如何在锁定时间屏幕中显示应用程序图标,就像锁定屏幕中的whatsapp徽标一样?
谢谢,维鲁