Urban Airship + Cordova 1.7+

时间:2012-06-07 20:09:24

标签: javascript ios cordova urbanairship.com

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

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

非常感谢!

2 个答案:

答案 0 :(得分:3)

我们使用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();
    }

答案 1 :(得分:3)

urbanairship在这里发布了android / ios的库和示例:https://github.com/urbanairship/phonegap-ua-push