【备忘】APNS 测试remote推送踩坑2022

1.用nodejs-apn测试
   先上可运行代码:

"use strict";
const apn = require("apn");
// token
let tokens = ["3122222d40f03b4024f81f04d8c2a3777b3ec35eb5604c7ab53d599bb84f59ff"];


let service = new apn.Provider({
    cert: "./certdev.pem",//你的生成的push证书pem 对应环境(沙盒或正式)
    key: "./keydev.pem",//你的生成的push私钥pem 对应环境(沙盒或正式)
  //   gateway: "api.development.push.apple.com",
    gateway: "gateway.sandbox.push.apple.com",//沙盒环境地址
    // gateway: "gateway.push.apple.com"; //正式环境地址
    // port: 2195, //
    pfx:"./xxxx.p12",//你生成的p12文件
    topic:"com.xxx.yyy",//你的bundleid
    passphrase: "123456"//你的私钥密码
  });

//发送的推送通知
let note = new apn.Notification({
    alert:  "sssssss-788788",
});

note.topic = "com.xxx.yyy"//

console.log(`Sending: ${note.compile()} to ${tokens}`);
service.send(note, tokens).then( result => {
    console.log("sent:", result.sent.length);
    console.log("failed:", result.failed.length);
    console.log(result.failed);
});

service.shutdown();

报错1原因:是因为service没填 pfx的参数

error: Error: Unable to load PFX certificate

报错2原因:填的topic不正确

failed: 2
[
  {
    device: 'xxx',
    status: '400',
    response: { reason: 'DeviceTokenNotForTopic' }
  }
]

2.用smartpush,开源xcode工程测试。
因版本久远,沙盒环境下,要修改 SecManager.mm文件的 isPushCertificate方法,添加一行代码:

|| [name rangeOfString:@"Apple Sandbox Push Services:"].location != NSNotFound

刚上github,看到有人提交了,这个问题应该不久后会合并解决的。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值