android - How to use push notifications in cordova app? -


i have strange problem... i'm using push notifications messaging in ionic app works time time... code is:

public initpushnotification() {     if (!this.platform.is('cordova')) {         console.warn('cordova 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 push plugin', error));             } else {                 alert('we not have permission send push notifications');             }         });     }); } 

it located in app.component.ts.

some of behavior:

  1. works fine when app minimized on cat s60 phone
  2. some times works when app minimized on cheap huawei
  3. some time works on both devices when app opened should be. in times not.

when send google receive ok status.

you can use 1 signal notifications. it's fast , effective. can detailed information links below.

https://documentation.onesignal.com/v3.0/docs/cordova-sdk-setup

https://www.npmjs.com/package/onesignal-cordova-plug

http://www.plugreg.com/plugin/one-signal/onesignal-cordova-sdk


Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -