【问题标题】:How to retrieve APID in Phone Gap Android application with Urban Airship plugin如何使用 Urban Airship 插件在 Phone Gap Android 应用程序中检索 APID
【发布时间】:2014-08-21 11:38:57
【问题描述】:

我正在尝试在 Android Phone Gap 应用程序中实现 Urban Airship。我正在使用 github 上的 Urban Airship Phone Gap 插件。我知道 Urban Airship 正在成功注册设备,因为:

  1. 它在 LogCat 中告诉我
  2. 该设备显示在我的 Urban Airship 设备中,我可以推送到它

我也可以像这样挂钩urbanairship.push 事件:

document.addEventListener("urbanairship.push", handleIncomingPush, false)
function handleIncomingPush(event) {
      if(event.message) {
        console.log("Incoming push: " + event.message)
      } else {
        console.log("No incoming message")
      }
    }

但是,由于某种原因,urbanairship.registration 事件没有触发。这是我的代码:

document.addEventListener("urbanairship.registration", onRegistration, false)
function onRegistration(event)  {
      if (!event.error) {
        console.log("Reg Success: " + event.pushID)
      } else {
        console.log('push registration error: ' + event.error)
      }
    }

我需要启动它,以便将设备的 APID 保存在我的后端。这两个都在我的onDeviceReady 回调中。

【问题讨论】:

    标签: android cordova urbanairship.com


    【解决方案1】:

    该插件似乎与 Cordova 3.0.0 不太兼容。我升级到 Cordova 3.1.0 (cordova-3.1.0.jar) 并将我的 Urban Airship 应用程序更改为生产而不是开发,并且它工作正常。

    【讨论】:

    • 嘿,我找到了一种通过 UA 的 JS API 获取 APID 的方法。它适用于我的开发和生产。
    【解决方案2】:

    我查看了 UA 的 PhoneGap Push 插件的源代码,它有一个可以检索您的 APID 的功能。

    deviceready 被触发后在下面使用它来检索您的 APID -

    PushNotification.enablePush(function() {
        console.log('push has been enabled');
        PushNotification.getPushID(function(apid) {
            console.log('got push apid, apid: ' + apid);
        });
    });
    

    我知道这肯定可以帮助任何人在未来寻求这个。这在 Android 上非常适合我,我很快就会在 iOS 上进行测试。

    您可以通过根 config.xml 像这样在应用启动时自动启用推送 -

    <!-- Enable push when the application launches (instead of waiting for enablePush js call).  Defaults to false -->
    <preference name="com.urbanairship.enable_push_onlaunch" value="true | false" />
    

    【讨论】:

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