简体   繁体   中英

Titanium Push Notification AeroGear

Im trying to send notifications to a Titanium App from AeroGear . After getting the token, how can subscribe to the channel?

Obteining the 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);
});

This is the example code for native Androiod :

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);
        }
    }
}

Really lost here, any help would be appreciated!

You need to make wrapper around AeroGear native library as titanium module . However, it may be difficult if you didn't it before.

要使它正常工作,需要的钛模块是由“ Mads”制造的,您可以在这里找到: https : //github.com/Napp/AeroGear-Push-Titanium

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM