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