我正在尝试关闭应用程序时使pushkit voip消息正常工作。当应用程序在前台或后台时,这些电话可以正常工作并显示。但是在用户强制杀死该应用程序之后,当收到通知时,该应用程序将终止并发出信号9(被用户/ ios杀死)。
如何解决此问题?
我在我的应用中启用了后台抓取,语音,音频和推送通知。还尝试删除所有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)
}
}
}
我正在尝试关闭应用程序时使pushkit voip消息正常工作。当应用程序在前台或后台时,这些电话可以正常工作并显示。但是,在用户强行杀死了...
问题是我的应用程序没有及时创建委托和pushregistry对象以完全处理通知。