我有一个应用程序,每分钟都会调用一个函数(每分钟调用一次函数是通过 setinterval 方法完成的。)我还在这个函数中实现了本地通知。分钟它将调用该函数,它将显示通知。我能够在每分钟后看到通知,这只在应用程序运行或最小化时发生,但是当我关闭应用程序时,此功能未被调用。我已经使用了后台模式插件,但是当应用程序被终止或清除时,它无效。
代码:
import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';
import { LocalNotifications } from '@ionic-native/local-notifications';
import {BackgroundMode} from '@ionic-native/background-mode';
import {Http,RequestOptions,Headers} from '@angular/http'
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
count:any;
content= "Yashwanth"
constructor(public navCtrl: NavController,public http: Http,public backgroundMode: BackgroundMode,private localNotifications: LocalNotifications) {
this.backgroundMode.enable();
}
a(){
let body:string ="&a=aksjd",
url:any = "http://some_site_name/abc.php",
type : string = "application/x-www-form-urlencoded; charset=UTF-8",
headers : any = new Headers({ 'Content-Type': type}),
options : any = new RequestOptions({ headers: headers });
this.http.post(url,body,options).subscribe((data) => {
let a = JSON.parse(data['_body']);
this.count = a['count'];
console.log(this.count);
this.localNotifications.schedule({
id: 1,
text: 'The count of ' + this.content + this.count
});
});
setInterval(()=>this.a(),60000);
}
ionViewDidLoad(){
this.a();
}
}