1

我正在使用 apn 模块(https://github.com/argon/node-apn)从 NodeJS 向 iPhone 发送推送通知。

我的代码在我的开发机器 (Mac OSX) 上运行良好,并且通过 Apple 沙箱网关 (gateway.sandbox.push.apple.com) 成功推送通知,但是当我将其移动到登台服务器(运行 Ubuntu)时,推送通知失败并显示以下消息:

 Error: ENOENT, no such file or directory 'apns-dev-cert.pem'

我正在这样设置 NodeJS apn 对象:

var options = {
    cert: "apns-dev-cert.pem",          
    key:  "apns-key.pem",               
    passphrase: null,   
    gateway: "gateway.sandbox.push.apple.com",              
    port: 2195,                         
    enhanced: true,                     
    errorCallback: undefined,                       
    cacheLength: 5                                  
};

在我的开发 Mac OSX 机器上,证书安装在钥匙串中。根据我对 Ubuntu 的有限理解,相当于将证书文件复制到 /etc/ssl/certs。我尝试这样做,并在我的 NodeJS 代码中将路径更改为“/etc/ssl/certs/apn-dev-cert.pem”,但出现了相同的错误消息。

有任何想法吗?

4

2 回答 2

3

我在这个问题上苦苦挣扎,直到我意识到我不了解fs模块如何读取文件。显然,它从您启动节点进程的目录中读取它们。因此,文件的路径.pem应该与您执行该操作的位置相关。

您可能也想签出 __dirname,这可能更容易指定您的路径

于 2012-11-06T23:07:48.850 回答
0

您尝试设置如下:

var options = {
    //cert: "apns-dev-cert.pem",          
    //key:  "apns-key.pem",               
    pfx: '<path>/apns-key.pem',    
    passphrase: null,   
    gateway: "gateway.sandbox.push.apple.com",              
    port: 2195,                         
    enhanced: true,                     
    errorCallback: undefined,                       
    cacheLength: 5                                  
};
于 2018-05-09T04:09:51.307 回答