Estoy usando el complemento push ngcordova para Android con marco iónico. Mi dispositivo se está registrando en GCM
. También obtengo la identificación de registro. Puedo almacenar la regid
tabla de usuarios. Todo funciona bien hasta ahora. Pero cuando envío la notificación desde mi servidor php, no puedo recibir la notificación en mi teléfono móvil. La respuesta del gcm al código php que obtengo es:
{"multicast_id":5214502018855543648,"success":1,"failure":0,"canonical_ids":0,"results":[{"message_id":"0:1439022666580761%156ac804f9fd7ecd"}]}
Mi código JavaScript es.
.run(function($ionicPlatform,ngFB,$state,$cordovaPush,$rootScope) {
$ionicPlatform.ready(function() {
// ------------------------------ GCM NG-CORDOVA PUSH-----------------------------------
var androidConfig = {
"senderID": "XXXXXXXXXX"
};
$cordovaPush.register(androidConfig).then(function(result) {
// Success
alert(result);
}, function(err) {
// Error
alert(err);
});
$rootScope.$on('$cordovaPush:notificationReceived', function(event, notification) {
switch(notification.event) {
case 'registered':
if (notification.regid.length > 0 ) {
alert('registration ID = ' + notification.regid);
$rootScope.reg_id = notification.regid;
}
break;
case 'message':
// this is the actual push notification. its format depends on the data model from the push server
alert('message = ' + notification.message + ' msgCount = ' + notification.msgcnt);
break;
case 'error':
alert('GCM error = ' + notification.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
});
// WARNING: dangerous to unregister (results in loss of tokenID)
// $cordovaPush.unregister(options).then(function(result) {
// Success!
//}, function(err) {
// Error
//})
});
})
Mi código php es:
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;
No entiendo dónde me equivoco. Por favor, ayúdame.
Gracias
Tuve el mismo problema una vez, recomiendo hacer su primera aplicación con el enlace de abajo y dejar que la segunda regid se asegure de que el dispositivo sea correcto, que se mantenga bien y que las claves de la aplicación sean correctas. Pruebe el mismo navegador para enviar notificaciones, a veces varían en el tiempo.
Este artículo se recopila de Internet, indique la fuente cuando se vuelva a imprimir.
En caso de infracción, por favor [email protected] Eliminar
Déjame decir algunas palabras