0

我正在尝试从AeroGear向 Titanium App 发送通知。获得token后,如何订阅频道?

获取令牌:

var CloudPush = require('ti.cloudpush');
var deviceToken = null;


CloudPush.retrieveDeviceToken({
    success: deviceTokenSuccess,
    error: deviceTokenError
});
function deviceTokenSuccess(e) {
    deviceToken = e.deviceToken;
}
function deviceTokenError(e) {
    alert('Failed to register for push notifications! ' + e.error);
}

CloudPush.addEventListener('callback', function (evt) {
    alert("Notification received: " + evt.payload);
});

这是本机 Android的示例代码:

package com.push.pushapplication;

import java.net.URI;
import java.net.URISyntaxException;

import org.jboss.aerogear.android.unifiedpush.PushConfig;
import org.jboss.aerogear.android.unifiedpush.PushRegistrar;
import org.jboss.aerogear.android.unifiedpush.Registrations;

import android.app.Application;

public class PushApplication extends Application {

    private final String VARIANT_ID       = "variant_id";
    private final String SECRET           = "secret";
    private final String GCM_SENDER_ID    = "1";
    private final String UNIFIED_PUSH_URL = "URL";

    private PushRegistrar registration;

    @Override
    public void onCreate() {
        super.onCreate();

        Registrations registrations = new Registrations();

        try {
            PushConfig config = new PushConfig(new URI(UNIFIED_PUSH_URL), GCM_SENDER_ID);
            config.setVariantID(VARIANT_ID);
            config.setSecret(SECRET);
            config.setAlias(MY_ALIAS);

            registration = registrations.push("unifiedpush", config);

            registration.register(getApplicationContext(), new Callback() {
                private static final long serialVersionUID = 1L;

                @Override
                public void onSuccess(Void ignore) {
                     Toast.makeText(MainActivity.this, "Registration Succeeded!",
                             Toast.LENGTH_LONG).show();
               }

               @Override
               public void onFailure(Exception exception) {
                     Log.e("MainActivity", exception.getMessage(), exception);
               }
            });

        } catch (URISyntaxException e) {
            throw new RuntimeException(e);
        }
    }
}

真的在这里迷路了,任何帮助将不胜感激!

4

2 回答 2

0

您需要将 AeroGear 本机库包装为钛模块。但是,如果您以前没有这样做,可能会很困难。

于 2015-05-03T05:49:59.600 回答
0

完成这项工作所需的钛模块由“Mads”制造,您可以在这里找到它:https ://github.com/Napp/AeroGear-Push-Titanium

于 2016-04-08T07:10:33.910 回答