【问题标题】:Is there a way to clear/set local notifications from the server?有没有办法从服务器清除/设置本地通知?
【发布时间】:2015-09-08 16:20:36
【问题描述】:

我正在使用meteor.js 和local notifications。我可以使用类似

cordova.plugins.notification.local.cancel([1, 2], function () {
    // Notifications were cancelled
}, scope);

从移动设备清除本地通知,但如果我想从另一台设备/计算机执行此操作,有没有办法?还是我需要使用推送通知?

【问题讨论】:

  • 您必须从设备重置本地通知,否则您需要推送通知。
  • 如果您希望从服务器(相同或 DDP 连接)发送通知并在客户端监听,我建议您使用 gunjansoni:notifications 包。 atmospherejs.com/gunjansoni/notifications

标签: cordova meteor notifications


【解决方案1】:

我没有使用那个包,但是应该可以做这样的事情:

Notifications = new Mongo.Collection("notifications");

if (Meteor.isClient) {
  Tracker.autorun(function() {
    var messages = Notifications.find({}).fetch();  // trigger autorun on change to collection
    console.log('cancel notification');
    cordova.plugins.notification.local.cancel([1, 2], function() {
      // Notifications were cancelled
    }, scope);
  });
}

if (Meteor.isServer) {
  Meteor.methods({
    cancelNotification: function() {
      Notifications.insert({message: 'cancel Notification'});
    },

  });
}

Meteor.call('cancelNotification') 在一个客户端中会触发所有已连接 客户端的自动运行。使用更多代码(过滤发布逻辑),您可以针对特定客户端和/或特定通知。

【讨论】:

  • 这是一个很酷的主意。所以我现在正在阅读Tracker.autorun,但它会在应用程序关闭时运行吗?
  • 如果它关闭,自动运行将不会触发。但是,此限制在原始问题的范围内,因为您只能在应用程序运行时清除(或安排)本地通知。当应用程序未运行时,您需要推送通知。
  • 这不是我想要的,但你是对的,它在原始问题的范围内。谢谢。
猜你喜欢
  • 2015-07-01
  • 1970-01-01
  • 2020-03-12
  • 1970-01-01
  • 2019-08-22
  • 2019-10-14
  • 2019-08-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多