Buscar..


Observaciones

El SenderID que está presente en el ejemplo de inicialización es un ID de remitente gcm que le proporciona Google. También debería estar presente al instalar el complemento.

ionic plugin add phonegap-plugin-push --variable SENDER_ID="XXXXXXX" 

Si desea agregar datos adicionales a sus notificaciones push, consulte este enlace que explica cómo agregar más tipografías https://github.com/phonegap/phonegap-plugin-push/blob/master/docs/TYPESCRIPT.md

Inicialización

El complemento de notificación de inserción requiere un inicio y una inicialización que le indica al complemento que comience a ejecutarse con la identificación del remitente proporcionada.

  let push = Push.init({
      android: {
        senderID: "------------",
      },
      ios: {
        alert: "true",
        badge: true,
        sound: "false",
      },
      windows: {},
    });

Registro

El paso de registro registra la aplicación con el sistema del dispositivo y devuelve un ID de registro

 import { Push, RegistrationEventResponse} from "ionic-native";

        //the push element is created in the initialization example
        push.on("registration", async (response: RegistrationEventResponse) => {
                    //The registration returns an id of the registration on your device
                    RegisterWithWebApi(response.registrationId);
    
        });

Recibir una notificación de inserción

Para recibir notificaciones push, se supone que debemos decirle al complemento que escuche las notificaciones push entrantes. Este paso se realiza después de la inicialización y registro.

import { Push, NotificationEventResponse} from "ionic-native";
      
        //the push element is created in the initialization example      
        push.on("notification", (response: NotificationEventResponse) => {
            let chatMessage: ChatMessage = <ChatMessage>{
              title: response.title,
              message: response.message,
              receiver: response.additionalData.replyTo,
              image: response.image
            };
            DoStuff(chatMessage));
       });


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow