2017-07-11 31 views
1

我正在爲我的表預定離子應用使用離子本地通知插件。我有一個控制Ionic App的Web儀表板。狀態變化時的離子本地通知觸發

當儀表板中的預定被批准並且狀態發生變化時,我試圖獲得本地通知以觸發。

我有通知工作很好,但我有一個重大問題,我想不通。

在離子應用程序中,用戶看到他們所有預訂的列表,然後當他們選擇預訂時,它打開包含對其預訂狀態(即,待定,批准或取消)的視覺參考的所有預訂細節的頁面。

這裏是我的組件:

export class OrderDetailsPage { 

    orderId: any; 
    orderDetails: any = { 
     status: '' 
    }; 
    booking: any = {}; 





    constructor(private localNotifications: LocalNotifications, public modalCtrl: ModalController, private calendar: Calendar, public af: AngularFireDatabase, private device: Device, private appAvailability: AppAvailability, private platform: Platform, public navCtrl: NavController, public navParams: NavParams) { 

     this.orderId = this.navParams.get('id'); 
     this.af.object('/orders/' + this.orderId).subscribe(res => { 
      this.orderDetails = res; 

      //Call my check status function to trigger notification 
      this.checkStatus(); 

      var orderId = res.orderId; 
      this.af.list('/bookings', { 
       query: { 
        orderByChild: 'orderId', 
        equalTo: orderId 
       } 
      }).subscribe(res => { 
       this.booking = res[0]; 
      }); 

     }) 



    } 



    checkStatus(){ 

     if (this.orderDetails.status == 'Accepted') { 
       this.localNotifications.schedule({ 
         id: 1, 
         title: 'Your Booking Was Accepted!', 
         text: 'Your booking has been Accepted by the restaurant!', 
         sound: '' 
        }); 
      } 
    } 
} 

將訂單從訂單列表頁面過去了,這有助於我獲得的特定順序來顯示訂單詳細信息頁面上。

我面臨的問題是通知只會觸發,當我直接進入無意義的訂單詳細頁面時。

我想要全局檢測,當特定用戶和特定訂單的狀態發生變化時,從Pending(在缺省情況下在Firebase中設置)到Approved,而不是當用戶進入訂單詳細信息頁面時。

我想過嘗試在應用程序根目錄中的代碼,但我無法從navParams中獲取要分配給orderId變量的id。

我甚至不確定我想要做什麼甚至可能與本地通知?

回答

0

對於該用例,您必須實現遠程通知。您將需要在服務器上添加一個掛鉤,因此當訂單更改時,您還會使用node-apns或Ionic Push等服務發送通知。本地通知不能用Ionic在後臺修改。

相關問題