gpt4 book ai didi

强制关闭后收到 pushkit voip 通知时 IOS 应用程序崩溃

转载 作者:行者123 更新时间:2023-12-01 16:20:31 25 4
gpt4 key购买 nike

我试图让 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)
}
}
}

最佳答案

问题是我的应用没有及时创建委托(delegate)和推送注册表对象来完全处理通知。

我通过覆盖应用委托(delegate)并将通知初始化放在 WillFinishLaunching 中解决了这个问题,如下所示:

-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions{
[CallPlugin registerVoIPPush:@"hmm"];
[super application:application willFinishLaunchingWithOptions:launchOptions];
return true;
}

这样,一切就绪,可以处理通知了。我试着先把它放在 DidFinishLaunching 中,但是通知已经太晚了,IOS 那时正在杀死我的应用程序。

关于强制关闭后收到 pushkit voip 通知时 IOS 应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61130352/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com