我正在使用CallKit和PushKit在Swift中开发软电话。在iOS 13之前,VoIP通知运行良好。但是在iOS 13更新之后,我的应用程序在后台运行时没有收到VoIP推送通知。在前台didReceiveIncomingPushWith
被调用,但在后台不被调用。
如何解决此问题?
代码
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
print("\(#function)")
let voipPushResgistry = PKPushRegistry(queue: nil)
voipPushResgistry.delegate = self
voipPushResgistry.desiredPushTypes = [PKPushType.voIP]
return true
}
func pushRegistry(_ registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
print("\(#function) token invalidated")
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate credentials: PKPushCredentials, for type: PKPushType) {
let deviceToken = credentials.token.reduce("", {$0 + String(format: "%02X", $1) })
print("\(#function) token is: \(deviceToken)")
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
print("\(#function)")
print("It worked..")
if type == .voIP {
print("Uygulama aktif")
}
}
感谢。
使用iOS 13 SDK]进行编译时,您将不再收到VoIP通知,也无法通过CallKit报告新的来话呼叫。
检查this other question,我已经解释了可用于不应该提醒新来电的通知的选项。
[如果您使用Xcode 11(和iOS 13 SDK)构建应用程序,则如果无法向CallKit报告,则PushKit将不再起作用。
Github上@mudassirzulfiqar的回答(谢谢他)。卸载并重新安装我的应用程序后,我收到了voip推送通知。现在,我将在reportNewIncomingCall
中调用didReceiveIncomingPushWith
。