cordovaを使用してハイブリットアプリを作成しています。
下記プラグインを使用してAndroidでプッシュ通知を行おうとしていますが、
アプリがバックグラウンドになった場合、プッシュ通知が送信されません。
アプリがフォアグランドの場合は問題なく送信されます。
下記参考サイトとほぼ同じに実装しています。
原因わかるでしょうか。
◎参考サイト
http://symfoware.blog68.fc2.com/blog-entry-1662.html
◎使用プラグイン
https://github.com/phonegap-build/PushPlugin
◎実装コード(devicereadyのタイミングで下記を実行しています)
lang
1var pushNotification; 2 3pushNotification = window.plugins.pushNotification; 4 5if (device.platform == 'android' || device.platform == 'Android') { 6 pushNotification.register( 7 successHandler, 8 errorHandler, { 9 "senderID": 12345678,//実際は正しいIDを設定しています。 10 "ecb": "onNotification" 11 }); 12} else { 13 // ios 14 pushNotification.register( 15 tokenHandler, 16 errorHandler, { 17 "badge": "true", 18 "sound": "true", 19 "alert": "true", 20 "ecb": "onNotificationAPN" 21 }); 22} 23 24function successHandler(result) { 25 console.log('result = ' + result); 26} 27 28function tokenHandler(result) { 29 console.log('device token = ' + result); 30} 31 32function errorHandler(error) { 33 console.log('error = ' + error); 34} 35 36function onNotificationAPN(event) { 37 if (event.alert) { 38 navigator.notification.alert(event.alert); 39 } 40 if (event.sound) { 41 var snd = new Media(event.sound); 42 snd.play(); 43 } 44 if (event.badge) { 45 pushNotification.setApplicationIconBadgeNumber(successHandler, errorHandler, event.badge); 46 } 47} 48 49// Android and Amazon Fire OS 50window.onNotification = function(e) { 51 switch (e.event) { 52 case 'registered': 53 if (e.regid.length > 0) { 54 console.log("regID(device token) = " + e.regid); 55 } 56 break; 57 case 'message': 58 if (e.foreground) { 59 alert(e.payload.default); 60 } else { 61 if (e.coldstart) { 62 console.log("=== message.background.coldstart ==="); 63 } else { 64 console.log("=== message.background.non coldstart ==="); 65 } 66 } 67 break; 68 case 'error': 69 console.log('error'); 70 break; 71 default: 72 break; 73 } 74};
あなたの回答
tips
プレビュー