[英]Urban Airship - Aggregating Similar Push Notifications on Messaging Platform
I am creating a messaging application, and like any mobile messaging service Push Notifications are needed for when the app isn't connected to the backend. 我正在创建一个消息传递应用程序,并且像任何移动消息传递服务一样,当应用程序未连接到后端时,也需要“推送通知”。
Let me use an example to out line the scenario I'm experiencing. 让我用一个例子概述我所遇到的情况。
There is a conversation between User A & User B
// User B's application is idle (not receiving messages from our backend)
// User A sends User B a message
A --> B
Because User B isn't connected, he/she is sent a push notification beckoning him/her to open the app and sync the message. 由于用户B未连接,因此系统会向他/她发送推送通知,要求他/她打开应用并同步消息。 User B's phone now has one notification on his/her lock screen, like so
用户B的电话现在在其锁定屏幕上有一个通知,就像这样
Message from User A
then ... 然后 ...
// User A sends User B another message
A --> B
User B's phone now has two separate notifications on his/her lock screen from User A. These messages read like this: 用户B的手机现在在其锁定屏幕上有来自用户A的两个单独的通知。这些消息的内容如下:
Message from User A
Message from User A
BUT, I would like the lockscreen to read something like this 但是,我希望锁屏读取这样的内容
Message from User A (2)
I am unsure how to get the notifications to aggregate once they reach the phone, assuming they have metadata attached to them that articulates who the "sender" of the message is. 我不确定在通知到达电话后如何收集这些通知,假设它们已附加了元数据,这些元数据清楚地表明了消息的“发送者”是谁。
Currently, this is the payload I am sending up to Urban Airship 目前,这是我要发送给Urban Airship的有效载荷
function sendPushNotification (event, user) {
if (event.type == 21 || event.type == 22 || event.type == 24) {
var sender = event.sender.username;
var alert = "from @" + sender;
var reciever = user.username;
var payload = {
"audience": {
"alias" : reciever
},
"device_types": [ "ios", "android" ],
"notification": {
"ios": {
"alert": alert,
"badge": "+1",
"sound": "default",
"extra": { "username": sender }
},
"android": {
"alert": alert,
"collapse_key": "inboxappco",
"extra": { "username": sender }
}
}
};
console.log("Hello 2");
pushNotification(payload);
} else {
// modularize for general purpose notifications
}
}; // end sendPushNotification function
Any advice on how I can leverage the the sender metadata, to aggregate consecutive push notifications from the same person into one line item on the lock screen? 关于如何利用发件人元数据将来自同一人的连续推送通知汇总到锁定屏幕上的一个订单项的任何建议?
Thanks in advance SOF. 在此先感谢SOF。
It appears that your app will need to create your own custom push notification object and somehow get access to the NotificationManager 您的应用似乎需要创建自己的自定义推送通知对象,并以某种方式获得对NotificationManager的访问权限
PushManager.shared().setNotificationBuilder(new YourCustomNotificationObject());
I'm not sure how Urban Airship exposes the NotificationManager, but you need to use the setGroup("arbitrarygroupname")
accessor in your NotificationBuilder 我不确定Urban Airship如何公开NotificationManager,但是您需要在NotificationBuilder中使用
setGroup("arbitrarygroupname")
访问器
Unless you are targeting minimum API level 20, then this is accessor is not available, so you have to use the v4+ NotificationCompat.Builder object, and make sure your support libraries are version 20 or higher. 除非您的目标是最低API级别20,否则访问器将不可用,因此您必须使用v4 + NotificationCompat.Builder对象,并确保您的支持库为版本20或更高版本。
EDIT, as of UrbanAirship 4.0.3 for Android this is not possible , server side you can keep track of a series of push notifications and use the collapse_key
parameters with each push, collapse_key
will replace push notifications of the same type, so your SERVER will have to send push notifications with different names, with the name being Message from User A (2)
instead of letting the Android system handle that client side 编辑,作为UrbanAirship 4.0.3的Android,这是不可能的 ,服务器端就可以跟踪一系列推送通知和使用
collapse_key
每推参数, collapse_key
将更换同一类型的推送通知,让您的服务器将必须发送具有不同名称的推送通知,名称为Message from User A (2)
而不是让Android系统处理该客户端
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.