public void onMessageReceived(RemoteMessage remoteMessage) {
// [START_EXCLUDE]
// There are two types of messages data messages and notification messages. Data messages are handled
// here in onMessageReceived whether the app is in the foreground or background. Data messages are the type
// traditionally used with GCM. Notification messages are only received here in onMessageReceived when the app
// is in the foreground. When the app is in the background an automatically generated notification is displayed.
// When the user taps on the notification they are returned to the app. Messages containing both notification
// and data payloads are treated as notification messages. The Firebase console always sends notification
// [END_EXCLUDE]
// TODO(developer): Handle FCM messages here.
// Not getting messages here? See why this may be:
Log.d(TAG, "From: " + remoteMessage.getFrom());
// Check if message contains a data payload.
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
}
// Check if message contains a notification payload.
if (remoteMessage.getNotification() != null) {
Log.d(TAG, "Message Notification Body: " + remoteMessage.getNotification().getBody());
}
// Also if you intend on generating your own notifications as a result of a received FCM
// message, here is where that should be initiated. See sendNotification method below.
}
您应该在FCM消息中发送数据有效载荷。无论应用程序处于前台还是后台,数据有效载荷都可以在消息方法中接收。处理那里的动作。例如通过始终读取数据负载来显示通知,或者如果您想在应用程序打开时或在前景中显示警报对话框。
下面是一个有效载荷示例:
{
"to": "registration_id_or_topic",
"data": {
"message": "This is a Firebase Cloud Messaging Topic Message!",
"youtubeURL": "https://youtu.be/A1SDBIViRtE"
}
}
则在您的OnMessageReceived中:
public void onMessageReceived(RemoteMessage remoteMessage) {
if (remoteMessage.getData().size() > 0) {
Log.d(TAG, "Message data payload: " + remoteMessage.getData());
Map<String, String> receivedMap = remoteMessage.getData();
String youtubeURL = receivedMap.get("youtubeURL");
showNotificationWithURLAction(youtubeURL);
}
.....
}
我正在使用FCM为我的iOS应用程序创建和发送推送通知。 开发环境: > Xcode 11.3 null 问题: 在遇到问题之前,我设置了我的应用程序,使其能够在应用程序处于后台和前台时接收通知。我对自己非常高兴,我promise了代码。在此之后,我无法在前台或后台接收通知。无论使用的通知是从云消息仪表板还是邮递员发送的,我都收到一个成功的响应但通知从未出现。 起初,我认为我可能已经达到通知配额,
我现在有这个问题,我需要在应用程序在后台时处理消息推送的信息,我的意思是,甚至不点击通知。这意味着这个应用程序:(UIApplication*)应用程序didReceiveRemote teNotify:(NSDicpedia*)userInfo fetchCompletionHandler:(val(^)(UIBackground FetchResult))完成必须在后台调用Handler!这是
我需要帮助。Firebase通知在后台不工作。这是我的代码:
我引用了前台和后台接收firebase通知的答案-->https://stackoverflow.com/A/38451582/12553303 其实下面是我的疑问:-------- 如果我没有为前台条件编码(谈论推送通知),当我的应用程序在后台时,我仍然会得到通知,对吗????-->是的 但是,当im处于前台状态时,我从firebase推送了一个通知-->我不会在状态栏上看到通知,这也是可以的(
问题内容: 由于JavaScript在单个线程中运行,因此在发出AJAX请求后,后台实际发生了什么?我想对此有更深入的了解,有人可以阐明吗? 问题答案: 在幕后,javascript具有事件队列。每次执行javascript线程完成时,它都会检查队列中是否还有其他事件要处理。如果存在,它将退出队列并触发该事件(例如,单击鼠标)。 位于ajax调用下的本机代码网络将知道ajax响应何时完成,并且事件