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

 幸福树袋熊2502903015 发布于 2023-02-12 14:47

我正在使用php,jquery和phonegap创建一个Android应用程序.我在谷歌搜索了很多东西,但我无法发送推送通知.我已经看过这个Phonegap和Parse.com推送通知IOS但我不清楚我可以获得deviceToken.

我也见过以下

https://parse.com/questions/php-rest-example-of-targeted-push

我明白了如何发送通知.但没有devicetoken我怎么能发送推送通知.Anybosy可以告诉我如何获得设备令牌.

1 个回答
  • 我按照本教程直接进行了很好的工作.它还解释了如何获取设备令牌.

    系统会提醒您输入它,但您也可以将手机连接到计算机并读取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

    2023-02-12 14:50 回答
撰写答案
今天,你开发时遇到什么问题呢?
立即提问
热门标签
PHP1.CN | 中国最专业的PHP中文社区 | PNG素材下载 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有