【发布时间】:2019-09-29 05:34:50
【问题描述】:
我正在使用 voip 推送通知制作 ios 应用程序。 我想从 node js 发送 voip 推送通知,但不是很好。
我阅读了本教程CallKit iOS Swift Tutorial for VoIP Apps (Super Easy),并使用 voip push 制作了 ios 应用程序。 我可以从 curl 命令发送 voip push。
curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert chara.pem:passphase https://api.push.apple.com/3/device/ede0d5e78f771d5916345aa48bd098e86aeab40b5e7d985fb9c74586d1a5a681
node index.js
const http2 = require('http2');
const fs = require('fs');
exports.handler = async (event) => {
const bundleID = 'com.swiswiswift.CharacterAlarm'
const deviceToken = 'ede0d5e78f771d5916345aa48bd098e86aeab40b5e7d985fb9c74586d1a5a681'
const headers = {
'apns-topic': bundleID
};
const options = {
protocol: 'https:',
method: 'POST',
hostname: 'api.push.apple.com',
path: '/3/device/' + deviceToken,
headers: headers,
cert: fs.readFileSync('chara.pem'),
passphrase: "passphrase"
};
const client = http2.connect('api.push.apple.com')
const req = client.request(options)
req.setEncoding('utf8')
req.on('response', (headers, flags) => {
console.log(headers)
});
let data = ''
req.on('data', (d) => data += d)
req.on('end', () => client.destroy())
req.end()
}
exports.handler('local-test')
[Object: null prototype] {
':status': 405,
'apns-id': 'xxxxxxx-xxxx-xxxx-xxx-xxxxxxxx' }
【问题讨论】:
-
我正在努力实现同样的目标。你成功了吗?
-
首先,如果您尝试将 Voip Push 用于发送呼叫以外的用途,它将无法正常工作,并且最终会从 iOS 13、Xcode 11 开始阻塞。无论如何,来自 Nodejs 的 VOIP 推送仍然是主题,请查看 stackoverflow.com/questions/36633188/…
-
执行 curl 命令时,我得到 "* Connection #0 to host api.push.apple.com {"reason":"BadDeviceToken"}* Closing connection 0"