###前提・実現したいこと
いろんなサイトを見ながら、cordovaでAndroidのプッシュ通知を実装しようとしましたが、うまくいきません。
トークンを取得するところで詰まってます。
###試した手順
- $ cordova create test
- $ cd test
- $ cordova platform add android
- $ cordova plugin add phonegap-plugin-push
- www/js/index.jsを下記に変更
js
1var app = { 2 // Application Constructor 3 initialize: function() { 4 document.addEventListener('deviceready', this.onDeviceReady.bind(this), false); 5 }, 6 // deviceready Event Handler 7 // 8 // Bind any cordova events here. Common events are: 9 // 'pause', 'resume', etc. 10 onDeviceReady: function() { 11 this.receivedEvent('deviceready'); 12 }, 13 14 // Update DOM on a Received Event 15 receivedEvent: function(id) { 16 var parentElement = document.getElementById(id); 17 var listeningElement = parentElement.querySelector('.listening'); 18 var receivedElement = parentElement.querySelector('.received'); 19 20 listeningElement.setAttribute('style', 'display:none;'); 21 receivedElement.setAttribute('style', 'display:block;'); 22 23 console.log('Received Event: ' + id); 24 }, 25 26 initPushNotification: function(){ 27 var push = PushNotification.init({ "android": {"senderID": "*********"}, 28 "ios": {"alert": "true", "badge": "true", "sound": "true"}, "windows": {} } ); 29 30 push.on('registration', function(data) { 31 // data.registrationId 32 console.log(data); 33 alert(data); 34 }); 35 36 push.on('notification', function(data) { 37 // data 38 }); 39 40 push.on('error', function(e) { 41 // e.message 42 }); 43 } 44 45 46}; 47 48app.initialize(); 49app.initPushNotification();
6. 実機(Android)をMacにつなぐ
7. cordova run android
8. 実機(Android)で実行される。
9. プッシュ通知に必要なトークンがアラートで表示されると期待するが、出ない。なぜ?
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。