2016-02-22 25 views
1

我目前正在使用MeteorJS的移动推送通知(android)。我现在用的是包:MeteorJS移动应用推送通知在后台

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 }); 
    } 
    }); 
}; 

一个非常直接的代码,只有在应用程序打开时才有效。我对背景通知的实际工作方式无能为力。谢谢

回答

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

什么结束了发生的事情是模板初始化的通知不上它应该是怎样运行的任何其他参数。如果您需要进一步的帮助,在软件包文档中对此进行了全面的说明。

+0

非常感谢你的回答,我会尽力解决你的问题。 –

+0

没问题!一定要接受答案,如果它最终为你工作,祝你好运! :) – TylerCompiler

+0

它在Android上正常工作,但在iOS上它没有:) –