Ionic Local Notifications 在状态改变时触发

Ionic Local Notifications trigger on status change

我正在为我的 Table 预订 ionic 应用程序使用 ionic 本地通知插件。我有一个控制 Ionic 应用程序的网络仪表板。

当仪表板中的预订获得批准并且状态发生变化时,我正在尝试触发本地通知。

我的通知运行良好,但我有一个我无法解决的重大问题。

在 ionic 应用程序中,用户会看到他们所有预订的列表,然后当他们 select 预订时,它会打开一个页面,其中包含所有预订详细信息,包括对其预订状态的视觉参考,即待定,已批准或已取消。

这是我的组件:

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

orderId 是从订单列表页面传递过来的,这有助于我获取特定订单以显示在订单详情页面上。

我面临的问题是通知仅在我真正进入毫无意义的订单详细信息页面时触发。

我想在全球范围内检测特定用户和特定预订的特定订单状态何时从待定(在 firebase 中默认设置)更改为已批准,而不是当用户进入订单详细信息页面时.

我想尝试应用程序根目录中的代码,但我无法从 navParams 获取 ID 以分配给 orderId 变量。

我什至不确定我想做什么甚至可以通过本地通知实现?

对于该用例,您必须实施远程通知。您需要在服务器上添加一个挂钩,因此当订单发生变化时,您还可以使用 node-apns 或 Ionic Push 等服务发送通知。无法使用 Ionic 在后台修改本地通知。