ios pushkit添加支持

1.添加权限:

https://www.jianshu.com/p/9afff11dd6af

2.添加代码:

//@available(iOS 8.0, *)

2.1调用voipRegistration

+    func voipRegistration() {

+        let mainQueue = DispatchQueue.main

+        // Create a push registry object

+        let voipRegistry: PKPushRegistry = PKPushRegistry(queue: mainQueue)

+        // Set the registry's delegate to self

+        voipRegistry.delegate = self

+        // Set the push type to VoIP

+        voipRegistry.desiredPushTypes = .init(arrayLiteral: PKPushType.voIP)

+    }

2.2 处理回调

extension AppDelegate: PKPushRegistryDelegate

{

 

    

     func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {

            let device = NSData(data: credentials.token)

            let devStr =  String.convertDataToHexStr(data:device)

            let deviceId = device.description.replacingOccurrences(of:"<", with:"").replacingOccurrences(of:">", with:"").replacingOccurrences(of:" ", with:"")

            HGLog("pushkit设备token:" + deviceId)

            HGLog("pushkit设备token devStr:" + devStr)

        }

        

        func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {

            var v = DateUtils.dateToString(Date())//ios 13 需要用这个转换

            v.append(":pushkit-didReceiveIncomingPushWith")

            UserDefaults.standard.setValue(v, forKey: "pushRegistryReceive")

            HGLog("收到pushkit推送!")

            HGLog(payload.dictionaryPayload)

          //  VideoCallManager.sharedInstance.playAlertSound()

            

    }

 

}

3.申请证书

https://dev.yunxin.163.com/docs/product/IM%E5%8D%B3%E6%97%B6%E9%80%9A%E8%AE%AF/SDK%E5%BC%80%E5%8F%91%E9%9B%86%E6%88%90/iOS%E8%8B%B9%E6%9E%9CPushKit%E9%85%8D%E7%BD%AE?kw=%E6%8E%A8%E9%80%81%E8%A7%92%E6%A0%87&pg=1&pid=0

3.1 转换证书格式(cer证书转换.p12文件)

https://blog.csdn.net/xiejunna/article/details/60967293?utm_source=blogxgwz0

3.2 p12 转 pem

openssl pkcs12 -clcerts -nokeys -out cert.pem -in cert.p12

openssl pkcs12 -nocerts -out key.pem -in key.p12

cat cert.pem key.pem > ck.pem

4.pushkit发送端:

https://github.com/stefanhafeneger/PushMeBaby 下载其中的php脚本,修改devicetoken和ck.pem,密码

4.1或者mac上下载APNS Tool可以发送一般通知或者pushkit 通知;

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值