1
Phonegap Build를 사용하면 Android 기기에 푸시 알림 요청을 사용하고 요청을 등록하고 무슨 일이 일어 났는지 확인할 수 있습니다! GCM 푸시 알림 등록 호출이 정상적으로 반환되지만 기기가 등록되지 않았습니다.
var pushNotification=window.plugins.pushNotification;
var return = pushNotification.register(successHandler , errorHandler,{"senderID":GCMProject,"ecb":"onNotification"});
function successHandler (result) {
alert('result = ' + result); // returned 'result = ok' //
}
function errorHandler (error) {
alert('error = ' + error);
}
function onNotification(e) {
$("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');
switch(e.event)
{
case 'registered':
if (e.regid.length > 0)
{
$("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
// Your GCM push server needs to know the regID before it can push to this device
// here is where you might want to send it the regID for later use.
console.log("regID = " + e.regid);
}
break;
case 'message':
// if this flag is set, this notification happened while we were in the foreground.
// you might want to play a sound to get the user's attention, throw up a dialog, etc.
if (e.foreground)
{
$("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');
// on Android soundname is outside the payload.
// On Amazon FireOS all custom attributes are contained within payload
var soundfile = e.soundname || e.payload.sound;
// if the notification contains a soundname, play it.
var my_media = new Media("/android_asset/www/"+ soundfile);
my_media.play();
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if (e.coldstart)
{
$("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
}
else
{
$("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
}
}
$("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
//Only works for GCM
$("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');
break;
case 'error':
$("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg + '</li>');
break;
default:
alert('EVENT -> Unknown, an event was received and we do not know what it is');
break;
}
}
successHandler()
언제 the onNotification()
방법이 언제 해고되지 않습니다 ???
아직 애플리케이션이 Play 스토어에 배포되지 않았습니다. 로컬로 사용되지만 인터넷에 연결됩니다.
의견을 보내 주셔서 감사합니다.
이 코드는 레지스터 만 사용합니다. 누가 통지를 보내고 있습니까? 이 메시지와 등록 정보를 Google 서버와 통신해야한다는 것을 고려하십시오. –
Puship.com을 사용하여 아래 링크에서 phonegap 빌드 api를 사용했습니다 : http://www.puship.com/documentations/ 플랫폼 - 설치/Phonegap 온라인 빌드,하지만 왜 응답이 '확인'메시지의 등록 ID를 instread 반환하지! –
푸시 알림을 보내거나 받기 전에 Google에서 기기 등록이 정확하고 GCM을 통해 완료되었는지 확인하고 싶습니다. –