我正在使用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")
}
}
感谢。