-
-
Save uno-de-piera/41d693cc22796900a5d9257988839235 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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