1、安装Node,下载地址:http://nodejs.org

2、更新npm,终端命令:sudo npm update npm -g

3、安装apn,终端命令:npm install apn

4、导出证书并生成pem文件

参照:http://www.tuicool.com/articles/fABVZb

5、Node源码:

var apns = require('apn');
var options = {
cert : 'cert.pem', /* Certificate file path */
key : 'key.pem', /* Key file path */
gateway : 'gateway.sandbox.push.apple.com',/* gateway address */
port: 2195, /* gateway port */
errorCallback: errorHappened , /* Callback when error occurs function(err,notification) */
};
function errorHappened(err, notification){
console.log("err " + err);
}
var apnsConnection = new apns.Connection( options );
var token = "<device token>";
var myDevice = new apns.Device( token );
var note = new apns.Notification();
note.expiry = Math.floor(Date.now() / 1000) + 3600; // Expires 1 hour from now.
note. badge = 11;
note. sound = "ping.aiff";
note. alert = "You have a new message";
note. payload = {'messageFrom': 'Caroline'};
note.device = myDevice; apnsConnection.sendNotification (note);

“<device token>”为接收push用的设备的DeviceToken字符串,不带空格及前后尖括号。

参考资料:http://www.tuicool.com/articles/fABVZb

最新文章

  1. gdb脚本
  2. Android中dp,px,sp概念梳理以及如何做到屏幕适配
  3. [转]STL中vector转数组(实际是数组的指针)
  4. JQuery EasyUI中datagrid的使用
  5. Javascrpt
  6. sql之表连接 筛选条件放在 连接外和放在连接里的区别
  7. Apache+php配置 Mysql安装出错解决办法
  8. Tomcat Remote Debug操作和原理
  9. java I/O框架 (三)基本流
  10. Matting任务里的Gradient与Connectivity指标
  11. UVA11987 Almost Union-Find
  12. pyqt5 添加属性-类方法用属性形式访问
  13. Selenium基础知识(二)鼠标操作
  14. Codeforces.666A.Reberland Linguistics(DP)
  15. linux中service的问题
  16. 在spring MVC 中关于session失效的判断 有一个类SessionStatus
  17. Django 自定义模板标签和过滤器
  18. 工作总结 vue 城会玩
  19. 第214天:Angular 基础概念
  20. NPOI操作Excel文件

热门文章

  1. codeforces round #234B(DIV2) A Inna and Choose Options
  2. JS中关于比较运算符的问题(a===b)
  3. 【BZOJ1088】[SCOI2005]扫雷Mine 递推
  4. ajax教程完整版
  5. JS写四个图片滚动显示的效果
  6. 做为一名dba你应该知道这些数据恢复
  7. 8点需要注意的Web编程小细节
  8. Joomla 3.2.0 - 3.4.4 无限制SQL注入漏洞
  9. Java实现智能机器自动操作电脑
  10. json转换数据后面参数要带ture,代码