繁体   English   中英

如何使用phonegap和parse发送推送通知

[英]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命令提示符下:

  1. phonegap create quickpush
  2. cd quickpush
  3. phonegap local build android
  4. phonegap local plugin add https://github.com/phonegap-build/PushPlugin

  5. 我跳过这个,我不把文件复制到www目录。 我把它放在原处。

  6. <script type="text/javascript" src="PushNotification.js"></script>到index.html

  7. <gap:plugin name="com.phonegap.plugins.pushplugin" />到config.xml(这与站点不同,解决了不支持的错误)

  8. 复制/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); } 
  9. 复制/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; } } 
  10. 构建应用程序: phonegap remote build android

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM