代码之家  ›  专栏  ›  技术社区  ›  Yokesh Varadhan

当应用程序被强制关闭(终止)时,本地通知不起作用

  •  0
  • Yokesh Varadhan  · 技术社区  · 7 年前

    我有一个php服务器,它向我发送了一组json,当json有任何变化时,我需要显示一些本地通知,所以我在 ionviewdidload() 我执行了这样的通知方法

    localnotification(){
        let notify_cuttent  = []; 
        this.httpClient.get(this.current).subscribe( tipList => {
            for (let i = 0; i < tipList['current_tips'].length; i++) {
                const element = tipList['current_tips'][i];
                notify_cuttent.push(element);
                if (notify_cuttent.length > this.CurrentList.length ||
                    notify_cuttent[i].call !== this.CurrentList[i].call ||
                    notify_cuttent[i].entry_price !== this.CurrentList[i].entry_price ||
                    notify_cuttent[i].special_note !== this.CurrentList[i].special_note ||
                    notify_cuttent[i].stop_loss !== this.CurrentList[i].stop_loss ||
                    notify_cuttent[i].take_profit_1 !== this.CurrentList[i].take_profit_1 ||
                    notify_cuttent[i].take_profit_2 !== this.CurrentList[i].take_profit_2   
                    ) {
                    console.log("higher length", );
                    let notify_title = notify_cuttent[i].instrument;
                    this.localNotifications.getAll().then(dataAll => {
                        console.log("notification it",dataAll.length, dataAll);
                        console.log(dataAll.length )
                        if (dataAll.length > 1) {
    
                            if (dataAll[i].text ==  'Check' +' '+ this.CurrentList[i].instrument +' '+ 'for new updates open app' 
                            ) {
                                console.log(i,"same text found nothing to be done")
                            } else {
                                console.log(i,"no text found",dataAll.length, notify_title);
                                //need to push a notification if there is no notification exist
                            }
                        } else {
                            console.log("no notification exist");
                            this.localNotifications.schedule({
                                id: dataAll.length + 1,
                                title: 'Current data',
                                text: 'Check' +' '+ notify_title +' '+ 'for new updates open app',
                                smallIcon: 'res://imgs/fox',
                                icon: 'file://assets/imgs/fox.jpg',
                                foreground: true
                            });
                        }
    
    
                    })
    
                }
            }
    
        })  
    }
    

    所以 notify_cuttent 具有来自php服务的json,以及 this.CurrentList 是移动设备中的本地数据,因此我将比较这些数据并发出通知

    我面临的问题 如果通知再次关闭,它将返回,直到我打开应用程序并查看 如果应用程序已从最近的视图强制关闭,我将不会收到通知

    有人能帮我一下吗

    0 回复  |  直到 7 年前