[英]how to send push notification using phonegap and parse
我正在使用php,jquery和phonegap創建一個Android應用程序。 我在谷歌搜索了很多東西,但我無法發送推送通知。 我已經看過這個Phonegap和Parse.com推送通知IOS但我不清楚我可以獲得deviceToken。
我也見過以下
https://parse.com/questions/php-rest-example-of-targeted-push
我明白了如何發送通知。 但沒有devicetoken我怎么能發送推送通知。 Anybosy可以告訴我如何獲得設備令牌。
我按照本教程直接進行了很好的工作。 它還解釋了如何獲取設備令牌。
系統會提醒您輸入它,但您也可以將手機連接到計算機並讀取logcat文件。 (你可以使用android SDK中的“監視器”工具)
更新示例
大多數步驟基本上都是我之前提到的devgirls教程的直接副本
在Windows命令提示符下:
phonegap create quickpush
cd quickpush
phonegap local build android
phonegap local plugin add https://github.com/phonegap-build/PushPlugin
我跳過這個,我不把文件復制到www目錄。 我把它放在原處。
將<script type="text/javascript" src="PushNotification.js"></script>
到index.html
將<gap:plugin name="com.phonegap.plugins.pushplugin" />
到config.xml(這與站點不同,解決了不支持的錯誤)
復制/js/index.js文件中onDeviceReady函數中的推送代碼。 顯然,從谷歌添加自己的密鑰
alert('device ready'); try { var pushNotification = window.plugins.pushNotification; pushNotification.register(app.successHandler, app.errorHandler,{"senderID":"--SENDER ID FROM GOOGLE--","ecb":"app.onNotificationGCM"}); } catch (ex) { alert('error: ' + ex); }
復制/js/index.js文件中的回調處理函數
successHandler: function(result) { alert('Callback Success! Result = '+result) }, errorHandler:function(error) { alert(error); }, onNotificationGCM: function(e) { switch( e.event ) { case 'registered': if ( e.regid.length > 0 ) { console.log("Regid " + e.regid); alert('registration id = '+e.regid); } break; case 'message': // this is the actual push notification. its format depends on the data model from the push server alert('message = '+e.message+' msgcnt = '+e.msgcnt); break; case 'error': alert('GCM error = '+e.msg); break; default: alert('An unknown GCM event has occurred'); break; } }
構建應用程序: phonegap remote build android
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.