Node js push-уведомление Apple с отправкой пользовательских данных

Теперь push-уведомление работает правильно, но я не знаю, как отправлять пользовательские данные с push-уведомлением.

Моя библиотека node js для push-уведомлений — «apn».

Код для push-уведомления:

    var apns = require('apn');

    /* Data to be send with push notification */
    var ntfnDetails = {};
    ntfnDetails = data.ntfnDetails;


    var options = {
        cert: 'FitCert.pem',                 /* Certificate file path */
        certData: null,                   /* String or Buffer containing certificate data, if supplied uses this instead of cert file path */
        key:  'FITHUDLEKEY.pem',                  /* Key file path */
        keyData: null,                    /* String or Buffer containing key data, as certData */
        passphrase: 'titech!@#',                 /* A passphrase for the Key file */
        ca: null,                         /* String or Buffer of CA data to use for the TLS connection */
        gateway: 'gateway.push.apple.com',/* gateway address */
        port: 2195,                       /* gateway port */
        enhanced: true,                   /* enable enhanced format */
        errorCallback: undefined,         /* Callback when error occurs function(err,notification) */
        cacheLength: 100                  /* Number of notifications to cache for error purposes */
    };

    var apnsConnection = new apns.Connection(options);

    var myDevice = data.device_id;

    var note = new apns.Notification();

    note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
    note.badge = 3;
    note.alert = 'Hellooo';
    note.payload = {'messageFrom': 'Caroline'};

    apnsConnection.pushNotification(note, myDevice);

В этом я хочу отправить переменную ntfnDetails с этим push-уведомлением.

Помогите пожалуйста найти решение...

Заранее спасибо.


person Reshma Reghunatha Panicker    schedule 25.11.2015    source источник


Ответы (1)


Я думаю, вы можете установить его в payload

note.payload = {'messageFrom': 'Caroline', 'ntfnDetails' : ntfnDetails };

Проверьте это apple-push-notification-with-sending-custom-data

person Trung    schedule 25.11.2015