极光推送 Node.js SDK 未指定环境时默认推送到开发环境,导致 iOS 设备没有收到推送消息。

查看 API 文档:https://github.com/jpush/jpush-api-nodejs-client/blob/master/doc/api.md
使用 setOptions 函数设置 options,本方法接收 5 个参数。

function setOptions (sendno, time_to_live, override_msg_id, apns_production, big_push_duration, apns_collapse_id, third_party_channel) {

}

实现代码如下:

npm install jpush-async --save

发送消息

const JPush = require('jpush-async').JPushAsync;

client.push().setPlatform(JPush.ALL)
    .setAudience(JPush.ALL)
    .setNotification('Hi, JPush', JPush.ios('ios alert', 'happy', 5))
    // 设置参数 apns_production 为 true 表示推送到生产环境
    .setOptions(null, null, null, true)
    .send();

标签: Node.js