Android の PushPlugin に問題があります。解決策を何時間も探してきましたが、まだ成功していません。
プッシュ通知を受け取っecb
ても起動しません。
登録時に正常に起動されますが、アプリを閉じて通知を受け取ると、通知をタップしてアプリを開くと呼び出されません。
ここに私のコードがあります:
var Utility = {
registerPushNotification : function() {
if( typeof device != 'undefined' )
{
// checking if device token is exist
var deviceToken = dbUtil.getValue('deviceToken');
if(deviceToken==null)
{
if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
window.plugins.pushNotification.register(
function(result) {
alert('result = ' + result);
},
function(error) {
alert('error = ' + error);
},
{
"senderID":'my_project_number',
"ecb":"Utility.onNotification"
}
);
} else if (device.platform == 'iOS'){
window.plugins.pushNotification.register(
function(result) {
// Your iOS push server needs to know the token before it can push to this device
// here is where you might want to send it the token for later use.
// alert('device token = ' + result);
dbUtil.setValue('deviceToken', result);
// upload deviceToken to server
Utility.registerDevice(result,app.CONSTANTS.TYPE_APNS);
},
function(error) {
// alert('error = ' + error);
pageUtil.drawToast('error getting device token');
},
{
"badge":"true",
"sound":"true",
"alert":"true",
"ecb":"Utility.onNotificationAPN"
});
}
}
}
},
onNotificationAPN : function (event) {
if ( event.alert )
{
navigator.notification.alert(event.alert);
}
if ( event.sound )
{
var snd = new Media(event.sound);
snd.play();
}
if ( event.badge )
{
// window.plugins.pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge);
}
},
// Android and Amazon Fire OS
onNotification : function(e) {
switch( e.event )
{
case 'registered':
{
if ( e.regid.length > 0 )
{
// 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.
// alert(e.regid);
// console.log("regID = " + e.regid);
dbUtil.setValue('deviceToken', e.regid);
// upload deviceToken to server
Utility.registerDevice(e.regid,app.CONSTANTS.TYPE_GCM);
}
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 )
{
// 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();
alert(e.payload.message);
}
else
{
pageUtil.loadingFullPage(true,e.payload.message);
// 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>');
}
}
break;
}
case 'error':
{
alert('error getting google notification');
break;
}
default:
{
break;
}
}
},
.....
};
これが私が登録する方法です。ecb
が呼び出され、次を取得できますregID
:
Utility.registerPushNotification();
しかし、e.event
= "メッセージ" が呼び出されない場合。
ノート:
window.plugins.pushNotification.register
一度だけ呼び出されます。register
アプリを起動するたびに呼び出す必要がありますか?