为Pushkit分配PKPushRegistryDelegate时如何消除类型错误?

问题描述 投票:0回答:1

我正在尝试创建VOIP调用应用程序,但得到“无法将'CallDelegate.Type'的值分配给'PKPushRegistryDelegate。

下面是我的代表班。该类继承PKPushRegistryDelegate并实现pushRegistry方法。不在AppDelegate中,因为我需要Init方法来初始化CallKit CXProvider(相同的错误,如果您将所有内容都放在AppDelegate中)。

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 {                
        }
    }

我已经在功能中启用了VOIP通知,并将Pushkit框架链接到了项目。针对IOS13。文档中的许多内容都无法立即使用(不建议使用的方法,名称等),也许注册表分配也已更改。

ios swift xcode callkit pushkit
1个回答
0
投票

问题是您的registerVoIPPush()方法是静态的,因此在这种情况下,self是指类型,而不是CallDelegate的实例。您必须将CallDelegate类的实例分配给PKPushRegistry委托。

© www.soinside.com 2019 - 2024. All rights reserved.