首页 > 解决方案 > 当应用程序关闭时,我可以从服务器调用我的通知功能吗?

问题描述

我想知道当我的应用程序关闭时是否可以从服务器调用我的应用程序中的函数?就像我的服务器收到新消息时调用本地通知功能一样。我的服务器在 nodejs 中,我正在使用 mongodb。谢谢 !

标签: cordovanotifications

解决方案


@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();
});
...

推荐阅读