1

现在推送通知可以正常工作,但我不知道如何使用推送通知发送自定义数据。

我用于推送通知的节点 js 库是“apn”。

推送通知代码:

    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”变量。

请帮助我找到解决方案...

提前致谢。

4

1 回答 1

2

我想你可以设置它payload

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

检查这个apple-push-notification-with-sending-custom-data

于 2015-11-25T04:40:50.897 回答