gpt4 book ai didi

node.js - Node js 苹果推送通知并发送自定义数据

转载 作者:太空宇宙 更新时间:2023-11-03 23:34:49 27 4
gpt4 key购买 nike

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

我的推送通知 Node 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”变量。

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

提前致谢。

最佳答案

我认为你可以在payload中设置它

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

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

关于node.js - Node js 苹果推送通知并发送自定义数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33908170/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com