【问题标题】:How to use push notifications in cordova app?如何在科尔多瓦应用程序中使用推送通知?
【发布时间】:2018-01-29 05:27:18
【问题描述】:

我有一些奇怪的问题...我在 Ionic 应用程序中使用推送通知进行消息传递,但它有时会起作用...我的代码是:

public initPushNotification() {
    if (!this.platform.is('cordova')) {
        console.warn('Cordova is not available - Run in physical device. Push notifications not initialized.');

        return;
    }

    let zone = new NgZone({ enableLongStackTrace: false });

    zone.run(() => {
        this.Push.hasPermission().then((res: any) => {
            if (res.isEnabled) {
                const options: PushOptions = {
                    android: {
                        senderID: GOOGLE_FCM_ID
                    }
                };

                let push_object = this.Push.init(options);

                push_object.on('registration').subscribe((data: any) => {
                    this.APIRequest.post('/messages/register-fcm-token', data).subscribe(response => {
                        console.log(response)
                    }, err => {
                        console.log(err)
                    })

                    console.log('push.registration', data);
                });

                push_object.on('notification').subscribe((data: any) => {
                    console.log('push.notification', data);

                    this.events.publish('messages:push', data.message);
                });

                push_object.on('error').subscribe(error => console.error('Error with Push plugin', error));
            } else {
                alert('We do not have permission to send push notifications');
            }
        });
    });
}

它位于app.component.ts

一些行为:

  1. Cat S60 手机上最小化应用时可以正常工作
  2. 有时在某些廉价的Huawei 上最小化应用程序时有效
  3. 当应用程序按原样打开时,两台设备上都有一些时间。大多数时候不是。

当我将它发送到 Google 时,我会收到 OK 状态。

【问题讨论】:

    标签: android cordova push-notification ionic2 cordova-plugins


    【解决方案1】:

    【讨论】:

      猜你喜欢
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-11-24
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-20
      相关资源
      最近更新 更多