只使用Android从cordova push插件获取字符串"OK"而不是设备/注册ID

 付帅sz_702 发布于 2022-12-08 23:09

我已经设置了推送通知插件并调用了register方法,但它只返回一个字符串"OK"而不是设备ID.我如何获得注册的设备ID?

   $window.plugins.pushNotification.register(
          function (result) {
            q.resolve(result); //this always just returns the string "OK", how do I get the device ID?
          },
          function (error) {
            console.log(error);
            q.reject(error);
          },
          config);

        return q.promise;
      },

e.regid为null,取自此示例

// Android and Amazon Fire OS
function onNotification(e) {
    $("#app-status-ul").append('
  • EVENT -> RECEIVED:' + e.event + '
  • '); switch( e.event ) { case 'registered': if ( e.regid.length > 0 ) { $("#app-status-ul").append('
  • REGISTERED -> REGID:' + e.regid + "
  • "); // Your GCM push server needs to know the regID before it can push to this device // here is where you might want to send it the regID for later use. console.log("regID = " + e.regid); } break; case 'message': // if this flag is set, this noti

    MonkeyBonkey.. 5

    所以我只是误解了推送库中的回调.iOS上的寄存器函数回调返回一个字符串标记,在Android中它只返回一个成功处理程序.Android版本中的注册事件的令牌ID必须在推送通知ecb处理程序而不是注册回调中处理.

    所以在他们的例子中

    if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
        pushNotification.register(
        successHandler,
        errorHandler,
        {
            "senderID":"replace_with_sender_id",
            "ecb":"onNotification"
        });
    } 
    

    该函数在config属性"ecb"中设置为"onNotification"而不是在sucess处理程序中.

    在这种情况下,您可以在原始问题中使用onNotification示例.我的错误是将onNotification函数作为Android中的成功处理程序传递,但实际情况并非如此.

    1 个回答
    • 所以我只是误解了推送库中的回调.iOS上的寄存器函数回调返回一个字符串标记,在Android中它只返回一个成功处理程序.Android版本中的注册事件的令牌ID必须在推送通知ecb处理程序而不是注册回调中处理.

      所以在他们的例子中

      if ( device.platform == 'android' || device.platform == 'Android' || device.platform == "amazon-fireos" ){
          pushNotification.register(
          successHandler,
          errorHandler,
          {
              "senderID":"replace_with_sender_id",
              "ecb":"onNotification"
          });
      } 
      

      该函数在config属性"ecb"中设置为"onNotification"而不是在sucess处理程序中.

      在这种情况下,您可以在原始问题中使用onNotification示例.我的错误是将onNotification函数作为Android中的成功处理程序传递,但实际情况并非如此.

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