【问题标题】:MeteorJS mobile app push notification in backgroundMeteorJS 移动应用程序在后台推送通知
【发布时间】:2016-06-03 13:29:50
【问题描述】:

我目前正在使用 MeteorJS 开发移动推送通知 (android)。我正在使用这个包:

https://github.com/katzer/cordova-plugin-local-notifications

应用程序打开时它工作正常,但关闭时没有任何反应。有没有办法使用这个包来使推送通知在应用程序关闭或最小化时也能正常工作?是否有可以做后台推送通知的流星替代包?到目前为止,这是我的代码:

if(Meteor.isCordova){

  Meteor.startup(function () {
    cordova.plugins.notification.local.registerPermission(function (granted) {
      if(confirm("Sample App would like to send you notifications: ") === true) {
        alert('permission granted '+granted)
      } else {
        alert('permission denied')
      }
    });

  });

  Template.hello.events({
    'click button': function () {
      var msg = $('[name=msg]').val();
      cordova.plugins.notification.local.add({ title: 'This is a sample push', message: msg });
    }
  });
};

仅在应用打开时才有效的非常简单的代码。我对后台通知的实际工作方式一无所知。谢谢

【问题讨论】:

    标签: cordova mobile meteor


    【解决方案1】:

    这是因为您还没有为通知创建schedule。如果应用程序没有运行,那么您为执行插件而编写的代码也不会运行,除非它被安排这样做,因此在应用程序加载并授予权限后创建一个后台进程。

    从以下位置更改通知的初始化:

    cordova.plugins.notification.local.add({ 
        title: 'This is a sample push', 
        message: msg });
    

    收件人:

    date = foo; //change this to when you want the notification to fire 
                //for the first time
    
    cordova.plugins.notification.local.**schedule**({
        id: 1,
        title: 'this is a sample push',
        message: msg,
        firstAt: date,
        every: 'minute' //set this to how often you want it repeated.
    )};
    

    最终发生的是模板初始化了通知,而没有任何关于它应该如何运行的进一步参数。如果您需要进一步的帮助,这一切都在包文档中得到了彻底的解释。

    【讨论】:

    • 非常感谢您的回答,我会尝试使用您的解决方案。
    • 没问题!如果它最终对您有用,请务必接受答案,祝您好运! :)
    • 嘿@WebsiteIsFun,抱歉回复晚了。如果你还没有弄清楚这一点,你介意告诉我当你在 iOS 上尝试这个时会发生什么吗?
    • 实际上iOS不允许本地通知,你必须使用推送通知才能使其在iOS中工作,所以我只是使用raix推送通知使其在ios和android上都可以工作
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-01-16
    • 2015-04-12
    • 1970-01-01
    相关资源
    最近更新 更多