IOS 强制关闭后收到 pushkit voip 通知时应用程序崩溃
IOS app crashing when recieving pushkit voip notification after force close
我试图让 pushkit voip 消息在应用程序关闭时工作。当应用程序在前台或后台时,调用工作并显示。但是在用户强制终止应用程序后,当收到通知时,应用程序终止并发出信号 9(被 user/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", [=11=]) }.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)
}
}
}
问题是我的应用程序没有及时创建委托和推送注册表对象来完全处理通知。
我通过覆盖应用委托并将通知初始化放在 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 消息在应用程序关闭时工作。当应用程序在前台或后台时,调用工作并显示。但是在用户强制终止应用程序后,当收到通知时,应用程序终止并发出信号 9(被 user/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", [=11=]) }.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)
}
}
}
问题是我的应用程序没有及时创建委托和推送注册表对象来完全处理通知。
我通过覆盖应用委托并将通知初始化放在 WillFinishLaunching 中解决了这个问题,如下所示:
-(BOOL)application:(UIApplication *)application willFinishLaunchingWithOptions:(nullable NSDictionary<UIApplicationLaunchOptionsKey,id> *)launchOptions{
[CallPlugin registerVoIPPush:@"hmm"];
[super application:application willFinishLaunchingWithOptions:launchOptions];
return true;
}
这样就可以处理通知了。我试着先把它放在 DidFinishLaunching 中,但是通知已经太晚了,IOS 那时我的应用程序已经被杀死了。