cordova - 当应用程序关闭时,我可以从服务器调用我的通知功能吗?
问题描述
我想知道当我的应用程序关闭时是否可以从服务器调用我的应用程序中的函数?就像我的服务器收到新消息时调用本地通知功能一样。我的服务器在 nodejs 中,我正在使用 mongodb。谢谢 !
解决方案
@Arzacks!
现在,你能让我给你看一些后端的片段吗?(这只是一个参考样本)
此示例使用 AWS SNS 进行推送通知。您应该注意 JSON PAYLOADS。由于
content-available
参数,通知处理程序作为后台进程注册到移动设备。在前端逻辑中,您应该处理cold-start
事件处理程序。
...
// compose push message
apnsJSON = {
aps: {
alert: 'PUSH MSG FROM APPLE',
sound: 'default',
'content-available': '1',
category: 'tabs.contact_pr', // param 4 client routing
},
// below are my custom params, ignore them
target: '4',
notId: '100204',
notWhen: fn_current_moment()
};
gcmJSON = {
data: {
message: 'PUSH MSG FROM FIREBASE',
sound: 'default',
'content-available': '1',
'force-start': '1',
category: 'tabs.contact_pr', // param 4 client routing
// below are my custom params, ignore them
target: '4',
notId: '100204',
notWhen: fn_current_moment()
}
};
var payload = JSON.stringify({
default: 'TESTING PUSH MSG',
APNS: JSON.stringify(apnsJSON),
APNS_SANDBOX: JSON.stringify(apnsJSON),
GCM: JSON.stringify(gcmJSON)
});
// AWS SNS publish now
// sending push to parent...
sns.publish({
Message: payload,
MessageStructure: 'json',
TopicArn: String(topic.topicARN)
}, function(err, data) {
if (err) {
console.log(err);
} else {}
callback();
});
...
推荐阅读
- mysql - 如何从数据库中计算总出席人数
- karate - 空手道 - 匹配两个动态响应
- makefile - 无法生成文件:“错误生成文件 XX:命令语法错误”
- python - 将一些文件附加到 MIME 多部分电子邮件
- jquery - 根据表详细信息名称和文本过滤表行
- html - 布尔玛下拉箭头未显示
- python - 无法安装 conda spyder 包构建
- odoo-11 - 如何在 Odoo 11 中将已安装模块的方法调用到另一个已安装模块中?
- sqlite - 如何统一读取sqlite db文件
- node.js - Node.js:将 JSON API 数据呈现为对服务器的 HTML 响应