Ionic Push problems


#1

Hello guys. How are you doing?
Well, I´m trying to use the Push plugin, which is phonegap-plugin-push, but I´m getting some difficult.
I´ve tried to make the example given in the Ionic documentation, but it didn´t work, actually the code doesn´t even compile.
Hope you guys can help me.
Thanks a lot.

here is the given example:

import { Push, PushObject, PushOptions } from '@ionic-native/push';

constructor(private push: Push) { }

...


// to check if we have permission
this.push.hasPermission()
  .then((res: any) => {

    if (res.isEnabled) {
      console.log('We have permission to send push notifications');
    } else {
      console.log('We do not have permission to send push notifications');
    }

  });

// Create a channel (Android O and above). You'll need to provide the id, description and importance properties.
this.push.createChannel({
 id: "testchannel1",
 description: "My first test channel",
 // The importance property goes from 1 = Lowest, 2 = Low, 3 = Normal, 4 = High and 5 = Highest.
 importance: 3
}).then(() => console.log('Channel created'));

// Delete a channel (Android O and above)
this.push.deleteChannel('testchannel1').then(() => console.log('Channel deleted'));

// Return a list of currently configured channels
this.push.listChannels().then((channels) => console.log('List of channels', channels))

// to initialize push notifications

const options: PushOptions = {
   android: {},
   ios: {
       alert: 'true',
       badge: true,
       sound: 'false'
   },
   windows: {},
   browser: {
       pushServiceURL: 'http://push.api.phonegap.com/v1/push'
   }
};

const pushObject: PushObject = this.push.init(options);


pushObject.on('notification').subscribe((notification: any) => console.log('Received a notification', notification));

pushObject.on('registration').subscribe((registration: any) => console.log('Device registered', registration));

pushObject.on('error').subscribe(error => console.error('Error with Push plugin', error));


#2

Two things.

First, could you format your code using the </> button so that it’s a bit more legible?

Second, what is the error message in particular that you’re getting?


#3

Hi my friend, i just edited the post as you told me.
first error: cant-resolve-all-parameters-for-push
and the other one is about PushOptions in that part of the code

const options: PushOptions = {
   android: {},
   ios: {
       alert: 'true',
       badge: true,
       sound: 'false'
   },
   windows: {},
   browser: {
       pushServiceURL: 'http://push.api.phonegap.com/v1/push'
   }
};

TS says that options are not possible for a PushOptions object