Skip to content

Instantly share code, notes, and snippets.

@uno-de-piera
Created May 23, 2018 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uno-de-piera/41d693cc22796900a5d9257988839235 to your computer and use it in GitHub Desktop.
Save uno-de-piera/41d693cc22796900a5d9257988839235 to your computer and use it in GitHub Desktop.
import { Push, PushObject, PushOptions } from '@ionic-native/push';
constructor(private push: Push) { }
...
// comprobamos los permisos
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');
}
});
// inicializamos la configuración para android y ios
const options: PushOptions = {
android: {
senderID: 'SENDER_ID'
},
ios: {
senderID: 'SENDER_ID'//si no lo pones, se generará un token para APNS
alert: 'true',
badge: true,
sound: 'false'
},
windows: {}
};
const pushObject: PushObject = this.push.init(options);
pushObject.on('notification').subscribe((notification: any) => {
//aquí recibimos las notificaciones de firebase
});
pushObject.on('registration').subscribe((registration: any) => {
const registrationId = registration.registrationId;
//registrationId lo debes guardar en mysql o similar para reutilizar
});
pushObject.on('error').subscribe(error => {
console.error('Error with Push plugin', error)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment