如何设置推送通知的格式,以便当它显示在状态栏上时,它可以利用本地通知的结构 - 显示文本并隐藏数据?
行为:当移动应用未运行时,推送通知会显示在设备的状态栏上。当用户单击状态栏上的通知时,通知将消失,应用程序将打开。虽然这是可接受的行为,但是原始推送通知未格式化以供用户在状态栏上查看。如何格式化推送通知,使其与状态栏(本地通知)查看更兼容?换句话说,隐藏数据但显示用户可读的文本?
插件:
.Net C#App服务代码:
string xml = "<ACTION>Add</ACTION>" +
"<UserId>" + ut.UserId + " </UserId>";
Dictionary<string, string> templateParams = new Dictionary<string, string>();
templateParams["messageParam"] = xml;
try
{
NotificationOutcome result = await
hub.SendTemplateNotificationAsync(templateParams, tagId);
config.Services.GetTraceWriter().Info(result.State.ToString());
return result;
}
以下是我的移动应用程序代码:
cordova.plugins.notification.local.on("click", function (notification) {
// Notification.text - contains whatever is in messageParam
// Notification.data - How do I format the app service code so that the
// xml shows up in Notification.data?
});
感谢您的帮助。
答案 0 :(得分:0)
以下是我的解决方案......
服务器端:
Dictionary<string, string> templateParams = new Dictionary<string, string>();
templateParams["messageParam"] = xmlNotification;
templateParams["titleParam"] = "testTitle";
templateParams["dataParam"] = "this is some data";
NotificationOutcome result = await
hub.SendTemplateNotificationAsync(templateParams, tagId);
config.Services.GetTraceWriter().Info(result.State.ToString());
客户端注册:
AzureDbSvc.client.push.register('gcm', handle, {
mytemplate: { body: { data: { message: "{$(messageParam)}", title: "{$(titleParam)}",
data: "{$(dataParam)}" } }, tags: arrTags }
客户端通知处理程序:
pushRegistration.on('notification', function (data) {
...
});
感谢Jeff Sanders提供以下文档......
我们(Azure&#39;)方面的基础知识:https://docs.microsoft.com/en-us/azure/notification-hubs/notification-hubs-aspnet-backend-gcm-android-push-to-user-google-notification
您想要的是自定义数据讯息:https://developers.google.com/cloud-messaging/concept-options#notifications_and_data_messages
消息参数:https://developers.google.com/cloud-messaging/http-server-ref
运行时的数据内容: