Ionic Angular运行一次计划通知

时间:2017-03-07 13:06:09

标签: angular ionic-framework ionic2

我正在构建一个应用程序,该应用程序每30分钟调用一次服务,以请求客户端剩余单元的值。在检查期间,如果客户端的单位低于指定的单位,则应用程序将发送单位运行不足的本地通知。一切正常。

我遇到的问题是,如果让我们说客户有90个单位且限制为100,该应用程序将发送通知罚款,但在30分钟后再次检查并看到客户端有85个单位,它将一次又一次地发送,直到客户充电。我想要的是发送一次的通知。任何帮助将不胜感激。以下是我的代码。

import matplotlib.pyplot as plt
import numpy as np
import matplotlib

params = {'legend.fontsize': 18,
      'axes.labelsize': 18,
      'axes.titlesize': 18,
      'xtick.labelsize' :12,
      'mathtext.fontset': 'cm',
      'mathtext.rm': 'serif', 
      "xtick.bottom" : False,
      "ytick.left" : False,
      }
matplotlib.rcParams.update(params)

f, axes = plt.subplots(nrows=2, sharex=True)

plt.subplots_adjust(hspace=0.001, bottom=0.2)

colors=["blue", "red"]

for i in [0,1]:
    data = np.loadtxt("ES{}.txt".format(i+1))
    POS = data[:,0]
    ESD = data[:,1]
    axes[i].plot(POS, ESD, color=colors[i], label="data{}".format(i))
    axes[i].legend(loc=4,prop={'size':10})

# make ticks invisble
axes[0].set_yticks([])
axes[1].set_yticks([])

plt.xlabel(r'$\mathrm{2\theta\ (deg)}$')
plt.xlim(15,80)

#create subplot just for placing the ylabel centered on all plots
shadowaxes = f.add_subplot(111, xticks=[], yticks=[], frame_on=False)
shadowaxes.set_ylabel(r'$\mathrm{Intensity\ (a.u)}$')

plt.savefig(__file__ + '.png', dpi=600,  bbox_inches='tight')  
plt.show()

1 个答案:

答案 0 :(得分:0)

您应该使用标记来识别应用程序启动时是否发送通知将密钥保存到名称为localstorage的{​​{1}},值为flag,并且通知为成功发送到客户端您可以将标志更改为false,如果确实如此,则不会发送通知。这将有助于您将localStorage替换为您的存储类型等。

true

当用户充值时,将标记设置为 this.storage.get('AlertOn100').then((val) => { var flag = localStorage.get("flag"); if (val==true && !flag){ if(res.power<100 && res.power>50){ LocalNotifications.schedule({ title: "Electricity is below 100 Units", text: "Please recharge to avoid running out", at: new Date(new Date().getTime() + 1 * 60 * 1000), sound: null }); localStorage.set("flag", true); console.log("Units Below 100 . The guy should be notified") }else{ console.log("Don't send notification at 100 Units because the units are above that value") } } }) ;

相关问题