【问题标题】:Urban Airship + Cordova 1.7+城市飞艇 + Cordova 1.7+
【发布时间】:2012-06-07 20:09:24
【问题描述】:

有没有人有 Urban Airship 使用 Cordova 1.7 的示例/插件/资源?

我遇到的所有示例和插件都是旧的。

非常感谢!

【问题讨论】:

    标签: javascript ios cordova urbanairship.com


    【解决方案1】:

    urbanairship 在此处发布了适用于 android/ios 的库和示例:https://github.com/urbanairship/phonegap-ua-push

    【讨论】:

      【解决方案2】:

      我们使用https://github.com/phonegap/phonegap-plugins/tree/master/iOS/PushNotification

      然后您需要将设备令牌发送到 UA - 我们使用这两个函数来执行此操作 - 在第一个中设置您的 app_key 和 secret。然后从某个地方调用它..

          function registerDevice(callback) {
              console.log("calling registerDevice");
              window.plugins.pushNotification.registerDevice({alert:true, badge:true, sound:true},function(status) {
                      if (status.deviceToken) {
                          window.token = status.deviceToken;
                          if (status) {
                              registerUAPush(token, "https://go.urbanairship.com/", "YOUR_APP_KEY", "YOUR_APP_SECRET", callback);
                          } else {
                              callback(false);
                              alert("error?");
                          }
                      }
              });
          }
      

      哪个调用

      function registerUAPush(deviceToken, host, appKey, appSecret, callback) {
      
              console.log('Registering with Urban Airship Push Service...');
      
              var request = new XMLHttpRequest();
      
              // open the client and encode our URL
              request.open('PUT', host+'api/device_tokens/'+deviceToken, true, appKey, appSecret);
      
              // callback when request finished
              request.onload = function() {
                  console.log('Status: ' + this.status + '<br>');
      
                  if(this.status == 200 || this.status == 201) {
                      // register UA push success
                      console.log('UA push service successfully registered.');
                  } else {
                    // error
                      console.log('Error when registering UA push service.<br>error: '+this.statusText);
                  }
      
                  callback(this.status == 200 || this.status == 201);
      
              };
      
              request.send();
          }
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多