I'm trying to create a VOIP calling application, but getting a "Cannot assign value of 'CallDelegate.Type'to 'PKPushRegistryDelegate.
Below is my delegate class. The class inherits PKPushRegistryDelegate and implements the pushRegistry methods. Not in AppDelegate because I need the Init method to init the CallKit CXProvider (same error, if you put everything in AppDelegate though).
import Foundation
import CallKit
import PushKit
class CallDelegate : NSObject, PKPushRegistryDelegate
{
private let provider: CXProvider
static func registerVoIPPush() {
let voipPushResgistry = PKPushRegistry(queue: DispatchQueue.main)
voipPushResgistry.delegate = self //**Getting the assign error here**
voipPushResgistry.desiredPushTypes = [PKPushType.voIP]
}
func pushRegistry( _ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
if type == PKPushType.voIP {
let tokenData = credentials.token
let voipPushToken = String(data: tokenData, encoding: .utf8)
//Send the POST request to oneSignal here
}
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
if type == .voIP {
if let handle = payload.dictionaryPayload["handle"] as? String,
let uuidString = payload.dictionaryPayload["uuid"] as? String,
let isVideo = payload.dictionaryPayload["isVideo"] as? Bool {
reportInComingCallWith(uuidString: uuidString, handle: handle, isVideo: isVideo)
}
}
}
func pushRegistry( _ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
}
func pushRegistry( _ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type:PKPushType, completion: @escaping () -> Void) {
if type == PKPushType.voIP {
}
}
I've enabled VOIP notifications in capabilities and linked the Pushkit framework to the project. Targeting IOS 13. A lot of things in the documentation don't work out of the box (deprecated methods, names, etc), maybe the registry assigning got changed as well.
The problem is that your registerVoIPPush()
method is static, hence in that context self
refers to the type and not to an instance of CallDelegate
. You have to assign an instance of your CallDelegate
class to the PKPushRegistry
delegate.