美文网首页
【Swift】PushKit(voip开发)--之获取pushT

【Swift】PushKit(voip开发)--之获取pushT

作者: 哗啦啦啦呃 | 来源:发表于2022-12-18 15:18 被阅读0次

记录一下我改的一个关于获取的pushToken在iOS15上能生效,但是在iOS16上不生效的bug

首先,获取token是在 pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {} 代理方法中的。

原获取方法:

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        print("voip 应用启动此代理方法会返回设备Token")
        guard type == PKPushType.voIP else {
            print("voip type is not voIP")
            return
        }
        if pushCredentials.token.count <= 0 {
            print("voip token nil")
            return
        }
var hexString : String = UnsafeBufferPointer<UInt8>(start: UnsafePointer(pushCredentials.token.bytes),
                                                            count: pushCredentials.token.count).map { String(format: "%02x", $0) }.joined(separator: "")
        hexString = hexString.replacingOccurrences(of: "<", with: "")
        hexString = hexString.replacingOccurrences(of: ">", with: "")
        hexString = hexString.replacingOccurrences(of: " ", with: "")
        print("voip token1 = \(hexString)")
}

这样获取在iOS15之前是有用的,但是因为iOS16对UnsafePointer(不安全指针)方法应该是有所修改,导致最后得不到正确的token,voip也就没办法推送了。
所以需要token转字符串的方法

新的方法:

func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
        print("voip 应用启动此代理方法会返回设备Token")
        guard type == PKPushType.voIP else {
            print("voip type is not voIP")
            return
        }
        if pushCredentials.token.count <= 0 {
            print("voip token nil")
            return
        }
        
        var hexString = pushCredentials.token.bytes.map{ String(format: "%02x", $0) }.joined(separator: "")
        hexString = hexString.replacingOccurrences(of: "<", with: "")
        hexString = hexString.replacingOccurrences(of: ">", with: "")
        hexString = hexString.replacingOccurrences(of: " ", with: "")
        print("voip token1 = \(hexString)")
    }

Over

相关文章

  • Voip Pushkit Callkit的使用

    1、Responding to VoIP Notifications from PushKit https://d...

  • iOS VOIP PushKit 开发相关

    前言 面对通话的通知需求,对方呼入,响起铃声和震动,提醒用户,对方挂断之后,铃声震动停止,普通的APNS通知,已经...

  • iOS Voip push部分笔记

    Voip push与普通push区分开的部分 引入PushKit头文件 #import 遵守协议 声明属性 @pr...

  • PJSIP开发VoIP记录2 - 配置

    PJSIP开发VoIP记录1 - 编译与集成 开发工具:Xcode9.2开发语言:swift 4.0 自从写了上一...

  • iOS中不一样的推送---PushKit

    PushKit是一种新的消息通知方式,旨在帮助voip应用(iOS 8)和watch OSComplication...

  • PJSIP开发VoIP记录1 - 编译与集成

    本文仅用于记录使用PJSIP开发VoIP,会陆续更新... 开发工具:Xcode9.2开发语言:swift 4.0...

  • iOS VOIP PushKit 基本配置

    前言 在做即时通讯实现音视频通话的时候,对方呼入,响起铃声和震动,提醒用户,对方挂断之后,铃声震动停止,普通的AP...

  • PushKit的使用

    1、为什么使用PushKit? iOS10之后,苹果推出了CallKit框架增强VoIP应用的体验,主要表现在3个...

  • iOS VOIP推送

    VOIP推送是在iOS8 之后提出来的,依赖PushKit.framework。 1. 应用场景 用于发送 类似微...

  • iOS VoIP实践

    简介 PushKit是苹果在iOS8之后推出的新框架,iOS10之后,苹果更是禁止VOIP应用在后台使用socke...

网友评论

      本文标题:【Swift】PushKit(voip开发)--之获取pushT

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