Как зарегистрировать приложение Cordova в Центре уведомлений Azure для отправки push-уведомлений - PullRequest
0 голосов
/ 14 февраля 2019

Я новичок в Apache Cordova и следую этому учебнику , чтобы включить push-уведомления в моем приложении с плагином: phonegap-plugin-push , но я не могу понятьузнать, как зарегистрировать устройство в Azure Hub.Нужно ли "создавать мобильное приложение" в службе Azure?Документация упоминается как «развертывание в существующем приложении», но информация все еще очень расплывчата, и я не могу понять, какую информацию о концентраторе необходимо предоставить в приложении.

В моем сценарии у меня уже есть УведомлениеКонцентратор, созданный вместе с ключом Api от Firebase для отправки на устройства Android.

var AZURE_MOBILE_APPS_ADDRESS = ''; //<-- What URL do you put here? I already tried the HUB but without success ...
var client;

if (AZURE_MOBILE_APPS_ADDRESS) {
    client = new WindowsAzure.MobileServiceClient(AZURE_MOBILE_APPS_ADDRESS);
}

...

// Register for push notifications. Requires that phonegap-plugin-push be installed.
var pushRegistration = null;

function registerForPushNotifications() {

    pushRegistration = PushNotification.init({
        android: { senderID: 'FIREBASE_PROJECT_NUMBER' },
        ios: { alert: 'true', badge: 'true', sound: 'true' },
        wns: {}
    });

    // Handle the registration event.
    pushRegistration.on('registration', function (data) {

        // Get the native platform of the device.
        var platform = device.platform;
        // Get the handle returned during registration.
        var handle = data.registrationId;
        // Set the device-specific message template.
        if (platform == 'android' || platform == 'Android') {
            // Register for GCM notifications.
            client.push.register('gcm', handle, {
                mytemplate: { body: { data: { message: "{$(messageParam)}" } } }
            });
        } else if (device.platform === 'iOS') {
            // Register for notifications.
            client.push.register('apns', handle, {
                mytemplate: { body: { aps: { alert: "{$(messageParam)}" } } }
            });
        } else if (device.platform === 'windows') {
            // Register for WNS notifications.
            client.push.register('wns', handle, {
                myTemplate: {
                    body: '<toast><visual><binding template="ToastText01"><text id="1">$(messageParam)</text></binding></visual></toast>',
                    headers: { 'X-WNS-Type': 'wns/toast' } }
            });
        }
    });

    pushRegistration.on('notification', function (data, d2) {
        alert('Push Received: ' + data.message);
    });

    pushRegistration.on('error', handleError);

}

Есть ли более поздний сценарий принудительного развертывания?

Любая помощь приветствуется!

...