我是靠谱客的博主 贪玩大神,最近开发中收集的这篇文章主要介绍node ios 远程消息推送笔记,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

  • 在基本配置在conf里production true和false对应源码config.js中apple远程生产和开发地址,相当智能,省略原来配置gateway 和port,其中gateway在新的版本中没发现应该是被废除了。
let EndpointAddress = {
production: "api.push.apple.com",
development: "api.development.push.apple.com"
};
复制代码
  • 具体实现代码
let tokens=['你的token'];//String|Array
let conf = {
cert:path.resolve(__dirname,"pem/apns-cer.pem"),
key: path.resolve(__dirname,"/pem/apns-cer-key.pem"),
production:false,
passphrase: "密码" //pem证书密码
}
let service = new apn.Provider(conf);
var note = new apn.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note.badge = 3;
note.alert = "sinoocean提示新消息。";
// 主题 一般取应用标识符(bundle identifier)
note.topic = "com.sinoocean.MobileMarket";
service.send(note, tokens).then( result => {
console.log("sent:", result.sent.length);
console.log("failed:", result.failed.length);
if(result.sent.length){
let id = result.sent.map(d=>d.device).join(",");
Log.trace(id+"发送消息成功。")
}
if(result.failed.length){
Log.error(result.failed);
}
});
}
复制代码

最后

以上就是贪玩大神为你收集整理的node ios 远程消息推送笔记的全部内容,希望文章能够帮你解决node ios 远程消息推送笔记所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(82)

评论列表共有 0 条评论

立即
投稿
返回
顶部