美文网首页
APNS 相关

APNS 相关

作者: iOS_Ru | 来源:发表于2019-03-07 11:00 被阅读0次

显示实现APNS 的方式有两种,一种是之前的push 证书的管理,另一种就是apns auth key。
推送证书有生产模式,开发者模式,使用起来非常的不方便。如果使用apns auth key就可以解决上述所有问题。所以还是建议大家使用auth key.
1.如何生成apns auth key?
首先你的是developer.apple.com 的admin权限 会看到证书那一列有个Keys 选项
<1>新建一个apns auth key,Name按照规则填写,然后选择APNs,点击continue


image.png

<2.>
点击 “Continue” 让你确认信息,再点击 “confirm”,就可以下载该 key了。(.p8 密钥文件)

(注意:记下 key id(.p8 密钥文件),而且只可以下载一次,请妥善保存。)

image.png

<3.>获取你之前创建过的应用的 Bundle ID
<4.>获取 Team ID
<5.>在推送平台控制台上,进入你应用的应用设置中 iOS 的鉴权方式选择 “Token Authentication”,上传 auth key 文件,并填写你的 KEY ID,TeamID,和指定应用的 BundleID。推送平台会在后台为你的应用进行鉴权


image.png

新的token验证推送,一个认证密钥可用于多个App服务,没有时效性。不用为每个App需要单独配置两个(开发环境和生产环境)证书,还要注意过没过期。

如何本地验证Auth key 配置的APNS

1.搭建测试环境,进入终端

mkdir apns
cd apns
npm init --yes  
npm install apn --save

2.编辑app.js文件,并将刚才下载的证书命名为apns.p8拷贝到apns目录下,需要注意production字段,是否是生产还是开发者环境通过这个字段来判断

var apn = require('apn');

// Set up apn with the APNs Auth Key
var apnProvider = new apn.Provider({  
     token: {
        key: 'apns.p8', // Path to the key p8 file
        keyId: 'ABCD12345', // The Key ID of the p8 file (available at https://developer.apple.com/account/ios/certificate/key)
        teamId: 'ABCD12345', // The Team ID of your Apple Developer Account (available at https://developer.apple.com/account/#/membership/)
    },
    production: true // Set to true if sending a notification to a production iOS app
});

// Enter the device token from the Xcode console
var deviceToken = '需要推送设备的devicetoken';

// Prepare a new notification
var notification = new apn.Notification();

// Specify your iOS app's Bundle ID (accessible within the project editor)
notification.topic = 'App的Bundle id';

// Set expiration to 1 hour from now (in case device is offline)
notification.expiry = Math.floor(Date.now() / 1000) + 3600;

// Set app badge indicator
notification.badge = 1;

// Play ping.aiff sound when the notification is received
notification.sound = 'ping.aiff';

// Display the following message (the actual notification text, supports emoji)
notification.alert = 'Hello World \u270C';

// Send any extra payload data with the notification which will be accessible to your app in didReceiveRemoteNotification
notification.payload = {id: 123};

// Actually send the notification
apnProvider.send(notification, deviceToken).then(function(result) {  
    // Check the result for any failed devices
    console.log(result);
});

3.运行app.js

node app.js

运行结果

{ sent:
   [ { device: '设备的devicetoken' } ],
  failed: [] }

如果推送成功就会直接推送到该设备上
如果推送失败 可以对应的查看相关错误
//可以查看官方文档
https://developer.apple.com/library/archive/documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/CommunicatingwithAPNs.html

image.png
image.png
image.png

参考
https://www.jianshu.com/p/b700f0237b0e

验证方式

相关报错查看

相关文章

  • APNs相关

    理解证书文件和描述文件 APNS原理和详解 SSL协议方式 APNs 各种证书之间的关系

  • APNS 相关

    显示实现APNS 的方式有两种,一种是之前的push 证书的管理,另一种就是apns auth key。推送证书有...

  • apns推送相关

    apns 推送

  • ios App上架流程小总结

    相关证书 : Certificates:开发者证书: 有权限开发APNs服务证书: 可以使用APNs服务器使用推送...

  • APNS 证书相关笔记

    生产&沙盒二合一推送证书### //下载的cer证书转pemopenssl x509 -in aps.cer -i...

  • 1.APNS推送相关

    1.APNs:Apple Push Notification server 苹果推送通知服务 App 向 iOS ...

  • iOS的APNS相关证书

    1生成苹果开发者APNS调试证书1.1登录苹果开发者账号,选择Apple Push Notification se...

  • APNS与VoIP

    APNS 一、简述APNS APNS全称是Apple Push Notification service(苹果推送...

  • iOS远程推送(Objective-C & Swift)

    iOS远程推送 APNS远程推送的流程: 1、app 注册到 APNS。2、APNS 下发 devicetoken...

  • iOS APNS

    APNS推送机制 APNS注意事项 1、APNS免费,但需要开发者账号2、APNS不稳定,Apple对消息推送的可...

网友评论

      本文标题:APNS 相关

      本文链接:https://www.haomeiwen.com/subject/pkgqpqtx.html