强制关闭后,当接收到Pushkit VoIP通知时,IOS应用程序崩溃

4
我正在尝试在应用关闭时使pushkit voip消息正常工作。 当应用处于前台或后台时,通话可以正常使用和显示。 但是,当用户强制关闭应用后,当通知被接收时,应用程序终止并显示信号9(由用户/ ios杀死)。
我该如何解决这个问题?
我已经在我的应用中启用了后台获取,voip,音频和推送通知。我还尝试删除所有Unity方法,将Callkit调用放入PushRegistry方法中,接收通知时创建新的提供程序,甚至订阅UIApplicationDidFinishLaunchingNotification事件,但什么都没有起作用。 我已经使应用程序符合在接收voip通知时显示呼叫的要求。以下是我的代码:
@objcMembers class CallPlugin: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate, CXProviderDelegate {

static var Instance: CallPlugin!
var provider: CXProvider!
var registry:PKPushRegistry!
var uuid:UUID!
var callController: CXCallController!

//class entry point
public static func registerVoIPPush(_ message: String) {
    Instance = CallPlugin()

    //Pushkit
    Instance.registry = PKPushRegistry(queue: DispatchQueue.main)
    Instance.registry.delegate = Instance
    Instance.registry.desiredPushTypes = [PKPushType.voIP]

    //Callkit
    let providerConfiguration = CXProviderConfiguration(localizedName: "testing")
    providerConfiguration.supportsVideo = true
    providerConfiguration.supportedHandleTypes = [.generic]
    Instance.provider = CXProvider(configuration: providerConfiguration)
    Instance.provider.setDelegate(Instance, queue: nil)        

    UnitySendMessage("ResponseHandler", "LogNative", "registration success")
}

//Get token
func pushRegistry( _ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
    if type == PKPushType.voIP {
        let deviceTokenString = credentials.token.map { String(format: "%02.2hhx", $0) }.joined()
        UnitySendMessage("ResponseHandler", "CredentialsRecieved",deviceTokenString)
    }
}       

//Get notification
func pushRegistry( _ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type:PKPushType, completion: @escaping () -> Void) {

    //UnitySendMessage("ResponseHandler", "LogNative", "Got something push")
    reportInComingCallWith(uuidString: "111", handle: "Paul", isVideo: false)
    completion()
}

//show the call
func reportInComingCallWith(uuidString:String,handle:String,isVideo:Bool) {
    //UnitySendMessage("ResponseHandler", "LogNative", "attempting call")
    let callUpdate = CXCallUpdate()        
    callUpdate.remoteHandle = CXHandle(type: .generic, value: handle)        
    callUpdate.hasVideo = false

    uuid = NSUUID() as UUID

    provider.reportNewIncomingCall(with: uuid as UUID, update: callUpdate){ (error) in
        if let error = error {
            UnitySendMessage("ResponseHandler", "LogNative", "error in starting call"+error.localizedDescription)
        }
    }
}

这是你的问题和解决方案。答案 - Kasım Özdemir
问题是一样的。因此,当应用程序在2到3次尝试中被禁止时,它将停止接收VoIP。您必须卸载并重新安装应用程序。 - Kasım Özdemir
@KasımÖzdemir 我知道应用程序被禁止的情况以及通过重新安装来解决问题,但这不是问题所在。当您被禁止时,该应用程序停止接收推送。我的应用程序没有停止接收它们,而是在发生此情况时崩溃并显示SIG-9。即使在重新安装后的第一次尝试中也是如此。我认为这不是授权问题,因为我在获取VOIP推送时确实调用了Callkit。 - Paul Vinogradov
您可以在Mac控制台应用程序中打开设备日志,查看是否有任何有用的信息。 - Paulw11
@Paulw11 检查了设备日志,发现出现了“终止原因0xbaadca11”的错误,这是一个CallKit错误,在此之前,一个线程崩溃并显示“0x56000080地址大小故障”。我猜测这是因为该类没有在appdelegate中初始化,而是稍后在应用程序中初始化。这是因为我在Unity应用程序中使用它。我已经更新了我的应用程序,从DidFinishLaunchingWith options事件调用初始化,但是应用程序在触发该事件后立即关闭,即使有打印语句也是如此。 - Paul Vinogradov
显示剩余2条评论
1个回答

1
问题在于我的应用程序没有及时创建委托和推送注册对象,以便完全处理通知。
我通过重写应用程序委托并将通知初始化放在WillFinishLaunching中解决了这个问题,如下所示:
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions{
   [CallPlugin registerVoIPPush:@"hmm"];
   [super application:application willFinishLaunchingWithOptions:launchOptions];
   return true;
}

这样一来,一切都准备就绪,可以处理通知了。我曾尝试在 DidFinishLaunching 中添加此项,但那时已经为通知晚了,IOS 会杀死我的应用程序。


我有同样的问题,而且我正在使用 Cordova。在我使用的插件中,我没有看到 "willFinishLaunchingWithOptions" 方法。你是从头开始写的吗? - alext
是的,这个实现是我自己写的。你可以将它或任何其他应用程序委托方法添加到主应用程序控制器中并覆盖它。 - Paul Vinogradov

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接