iOS VoIP(Pushkit)应用在后台崩溃,但在前台正常工作

3
我正在使用PushKit/CallKit开发我的Swift应用程序,它是纯Swift、在Xcode 13.1上测试,使用iOS 15和iOS 14.7(两个物理设备)+PHP后端。在测试过程中,我发现每次语音推送接收事件时,无论它是在后台还是未启动,我的应用都会崩溃。只有当它在前台时,一切正常,所有情况都被处理,推送也是OK的,呼叫也能被报告,应用程序按预期工作。我认为这是由于[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes]+192引起的。你可以在下面看到完整的崩溃日志。在沙盒(从Xcode构建的开发版本)和生产(adhoc分发版本)苹果APN网址上均出现相同的问题。我的问题是:为什么我的应用程序在前台运行正常(所有推送都能正确地报告到CallKit),而在后台却无法报告某些事情?难道在我的AppDelegate中的一个方法func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion:@escaping () -> Void)中不应该是相同的逻辑吗?是否存在必须特别处理VoIP推送的应用程序启动或进入前台的情况?我已经为此挣扎了5天,这里任何帮助都将不胜感激!一些背景:它是基于WKWebView的应用程序,其中PushKit部分旨在通过从服务器发送的推送发起视频呼叫(通话本身在网页上完全运行,使用Agora引擎)。重点在于让应用程序知道以下内容: - 电话即将开始(例如,有人坐在网页上并给我打电话) - 电话正在更改其状态(例如,接听电话) - 电话未被接听或拒绝 - 电话结束(例如,我正在与某人交谈,他挂断了电话并离开了对话) 我如何处理它(简要逻辑说明):接收推送,检查其有效载荷,根据需要启动新呼叫(报告到CallKit)或更新呼叫(我已经向CallKit报告一个呼叫)。然后,根据负载JSON中的操作字段,我正在执行各种操作,例如(如上所述)开始新呼叫、接受呼叫(例如,移动到Web视图中的某个特定页面)、将我的状态返回到服务器、结束正在进行的呼叫等。无论如何(这很重要!),我将ANY推送报告给CallKit作为新呼叫,在其他地方回答、拒绝、结束等。

我没有任何情况不向CallKit报告信息,但唯一可能的情况是当我收到的推送在负载中没有“action”字段时(例如,推送来自未知结构、格式错误或已损坏)。现在,话虽如此,我也考虑使用CallKit处理这种情况,无论是拒绝还是类似的操作。

Date/Time:           2022-02-20 21:27:33.7032 +0300
Launch Time:         2022-02-20 21:27:33.6191 +0300
OS Version:          iPhone OS 15.2.1 (19C63)
Release Type:        User
Baseband Version:    2.23.02
Report Version:      104

Exception Type:  EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note:  EXC_CORPSE_NOTIFY
Triggered by Thread:  0

Application Specific Information:
abort() called


Last Exception Backtrace:
0   CoreFoundation                         0x180bd50fc __exceptionPreprocess + 220
1   libobjc.A.dylib                        0x19940fd64 objc_exception_throw + 60
2   Foundation                             0x18248f3ac _userInfoForFileAndLine + 0
3   PushKit                                0x1b3a53d80 -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes] + 192
4   libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
5   libdispatch.dylib                      0x1808568c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
6   PushKit                                0x1b3a52ee0 __73-[PKPushRegistry voipPayloadReceived:mustPostCall:withCompletionHandler:]_block_invoke + 540
7   libdispatch.dylib                      0x180845924 _dispatch_call_block_and_release + 32
8   libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
9   libdispatch.dylib                      0x180855b70 _dispatch_main_queue_callback_4CF + 944
10  CoreFoundation                         0x180b8dd84 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
11  CoreFoundation                         0x180b47f5c __CFRunLoopRun + 2540
12  CoreFoundation                         0x180b5b468 CFRunLoopRunSpecific + 600
13  GraphicsServices                       0x19c6e638c GSEventRunModal + 164
14  UIKitCore                              0x1834fd088 -[UIApplication _run] + 1100
15  UIKitCore                              0x18327b958 UIApplicationMain + 2092
16  Doctor                                 0x102eae2c8 main + 25288 (__hidden#331_:18)
17  dyld                                   0x10315daa4 start + 520

Thread 0 name:   Dispatch queue: com.apple.pushkit.ivarqueue
Thread 0 Crashed:
0   libsystem_kernel.dylib                 0x1b8271964 __pthread_kill + 8
1   libsystem_pthread.dylib                0x1f1ead378 pthread_kill + 268
2   libsystem_c.dylib                      0x18ba98f50 abort + 164
3   libc++abi.dylib                        0x199517bc4 abort_message + 132
4   libc++abi.dylib                        0x199508fd8 demangling_terminate_handler() + 332
5   libobjc.A.dylib                        0x199415e34 _objc_terminate() + 144
6   libc++abi.dylib                        0x199516f58 std::__terminate(void (*)()) + 20
7   libc++abi.dylib                        0x199516ef4 std::terminate() + 64
8   libdispatch.dylib                      0x180847684 _dispatch_client_callout + 40
9   libdispatch.dylib                      0x1808568c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
10  PushKit                                0x1b3a52ee0 __73-[PKPushRegistry voipPayloadReceived:mustPostCall:withCompletionHandler:]_block_invoke + 540
11  libdispatch.dylib                      0x180845924 _dispatch_call_block_and_release + 32
12  libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
13  libdispatch.dylib                      0x180855b70 _dispatch_main_queue_callback_4CF + 944
14  CoreFoundation                         0x180b8dd84 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 16
15  CoreFoundation                         0x180b47f5c __CFRunLoopRun + 2540
16  CoreFoundation                         0x180b5b468 CFRunLoopRunSpecific + 600
17  GraphicsServices                       0x19c6e638c GSEventRunModal + 164
18  UIKitCore                              0x1834fd088 -[UIApplication _run] + 1100
19  UIKitCore                              0x18327b958 UIApplicationMain + 2092
20  Doctor                                 0x102eae2c8 main + 25288 (__hidden#331_:18)
21  dyld                                   0x10315daa4 start + 520

Thread 1 name:   Dispatch queue: com.apple.network.connections
Thread 1:
0   libnetwork.dylib                       0x18198b820 nw_frame_create + 0
1   libnetwork.dylib                       0x18198e778 nw_channel_create_frame + 72
2   libnetwork.dylib                       0x1819758b4 nw_channel_create + 1116
3   libnetwork.dylib                       0x181996438 nw_channel_create_with_attributes + 288
4   libnetwork.dylib                       0x181839340 nw_endpoint_flow_attach_channel_protocol + 1332
5   libnetwork.dylib                       0x1819b6df8 nw_endpoint_flow_attach_protocols + 8780
6   libnetwork.dylib                       0x181836bc0 nw_endpoint_flow_setup_protocols + 3956
7   libnetwork.dylib                       0x18183ae38 nw_endpoint_flow_setup_channel + 1944
8   libnetwork.dylib                       0x18183120c -[NWConcrete_nw_endpoint_flow updatePathWithHandler:] + 2340
9   libnetwork.dylib                       0x18189539c nw_endpoint_handler_path_change + 1800
10  libnetwork.dylib                       0x181afc9cc __nw_endpoint_handler_initialize_association_block_invoke + 156
11  libnetwork.dylib                       0x181d0aa6c __nw_association_update_paths_block_invoke.81 + 92
12  libnetwork.dylib                       0x1818922e0 nw_hash_table_apply + 168
13  libnetwork.dylib                       0x181d0a37c nw_association_update_paths + 488
14  libnetwork.dylib                       0x18198d190 nw_path_necp_update_evaluator + 1996
15  libnetwork.dylib                       0x18196f340 nw_path_necp_check_for_updates + 876
16  libnetwork.dylib                       0x1818dd7b4 nw_path_evaluator_force_update + 128
17  libnetwork.dylib                       0x181d0d5b4 nw_association_force_update + 108
18  libnetwork.dylib                       0x18183c8b0 nw_endpoint_flow_setup_channel + 8720
19  libnetwork.dylib                       0x181832d8c -[NWConcrete_nw_endpoint_flow startWithHandler:] + 3608
20  libnetwork.dylib                       0x18189539c nw_endpoint_handler_path_change + 1800
21  libnetwork.dylib                       0x1818c2080 nw_endpoint_handler_start + 1096
22  libnetwork.dylib                       0x18182e9e0 nw_endpoint_resolver_start_next_child + 4168
23  libdispatch.dylib                      0x180845924 _dispatch_call_block_and_release + 32
24  libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
25  libdispatch.dylib                      0x180850dac _dispatch_workloop_invoke + 2092
26  libdispatch.dylib                      0x18085a1b8 _dispatch_workloop_worker_thread + 656
27  libsystem_pthread.dylib                0x1f1ea70f4 _pthread_wqthread + 288
28  libsystem_pthread.dylib                0x1f1ea6e94 start_wqthread + 8

Thread 2:
0   libsystem_pthread.dylib                0x1f1ea6e8c start_wqthread + 0

Thread 3:
0   libsystem_pthread.dylib                0x1f1ea6e8c start_wqthread + 0

Thread 4 name:  com.apple.uikit.eventfetch-thread
Thread 4:
0   libsystem_kernel.dylib                 0x1b826b504 mach_msg_trap + 8
1   libsystem_kernel.dylib                 0x1b826bb9c mach_msg + 76
2   CoreFoundation                         0x180b43738 __CFRunLoopServiceMachPort + 372
3   CoreFoundation                         0x180b47a2c __CFRunLoopRun + 1212
4   CoreFoundation                         0x180b5b468 CFRunLoopRunSpecific + 600
5   Foundation                             0x182377c94 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 236
6   Foundation                             0x1823b8dc8 -[NSRunLoop(NSRunLoop) runUntilDate:] + 92
7   UIKitCore                              0x183476230 -[UIEventFetcher threadMain] + 524
8   Foundation                             0x1823c740c __NSThread__start__ + 808
9   libsystem_pthread.dylib                0x1f1ea79a4 _pthread_start + 148
10  libsystem_pthread.dylib                0x1f1ea6ea0 thread_start + 8

Thread 5:
0   libsystem_pthread.dylib                0x1f1ea6e8c start_wqthread + 0

Thread 6 name:   Dispatch queue: com.apple.coreaudio.ASClientManager
Thread 6:
0   libsystem_kernel.dylib                 0x1b826b504 mach_msg_trap + 8
1   libsystem_kernel.dylib                 0x1b826bb9c mach_msg + 76
2   libdispatch.dylib                      0x1808660d0 _dispatch_mach_msg_send + 700
3   libdispatch.dylib                      0x18086596c _dispatch_mach_send_drain + 344
4   libdispatch.dylib                      0x180861eec _dispatch_mach_send_msg + 364
5   libdispatch.dylib                      0x1808621b4 _dispatch_mach_send_and_wait_for_reply + 304
6   libdispatch.dylib                      0x18086263c dispatch_mach_send_with_result_and_wait_for_reply + 56
7   libxpc.dylib                           0x1f1ecfb9c xpc_connection_send_message_with_reply_sync + 240
8   CoreFoundation                         0x180c04cd0 __104-[CFPrefsSearchListSource synchronouslySendDaemonMessage:andAgentMessage:andDirectMessage:replyHandler:]_block_invoke_2 + 40
9   CoreFoundation                         0x180bd17a8 -[_CFXPreferences withConnectionForRole:performBlock:] + 52
10  CoreFoundation                         0x180bf44cc __104-[CFPrefsSearchListSource synchronouslySendDaemonMessage:andAgentMessage:andDirectMessage:replyHandler:]_block_invoke + 140
11  CoreFoundation                         0x180c0cd60 CFPREFERENCES_IS_WAITING_FOR_SYSTEM_CFPREFSD + 100
12  CoreFoundation                         0x180c2b59c -[CFPrefsSearchListSource synchronouslySendDaemonMessage:andAgentMessage:andDirectMessage:replyHandler:] + 332
13  CoreFoundation                         0x180b828d4 -[CFPrefsSearchListSource alreadylocked_generationCountFromListOfSources:count:] + 232
14  CoreFoundation                         0x180b71db4 -[CFPrefsSearchListSource alreadylocked_getDictionary:] + 468
15  CoreFoundation                         0x180bd260c -[CFPrefsSearchListSource alreadylocked_copyValueForKey:] + 172
16  CoreFoundation                         0x180c39a08 -[CFPrefsSource copyValueForKey:] + 60
17  CoreFoundation                         0x180b73e2c __76-[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:]_block_invoke + 44
18  CoreFoundation                         0x180b933b8 __108-[_CFXPreferences(SearchListAdditions) withSearchListForIdentifier:container:cloudConfigurationURL:perform:]_block_invoke + 404
19  CoreFoundation                         0x180b6b3d8 normalizeQuintuplet + 356
20  CoreFoundation                         0x180b6445c -[_CFXPreferences withSearchListForIdentifier:container:cloudConfigurationURL:perform:] + 152
21  CoreFoundation                         0x180bc219c -[_CFXPreferences copyAppValueForKey:identifier:container:configurationURL:] + 168
22  CoreFoundation                         0x180b88588 _CFPreferencesCopyAppValueWithContainerAndConfiguration + 128
23  libAudioToolboxUtility.dylib           0x199da3b3c CACFPreferencesGetAppIntegerValue(__CFString const*, __CFString const*, bool*) + 28
24  AudioToolboxCore                       0x19399b28c GetMediaServerRPCTimeout() + 112
25  AudioToolbox                           0x18b6ec404 invocation function for block in AudioSessionClientManager::Instance() + 172
26  libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
27  libdispatch.dylib                      0x180848f18 _dispatch_once_callout + 32
28  AudioToolbox                           0x18b6ef660 invocation function for block in AudioSessionClientManager::CreatePrimaryClient(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*) + 564
29  libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
30  libdispatch.dylib                      0x1808568c4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
31  AudioToolbox                           0x18b6eea80 AudioSessionClient::InitializeAudioSessionClient(__CFRunLoop*, __CFString const*, void (*)(void*, unsigned int), void*, AudioSessionType, __CFString const*, unsigned int) + 832
32  AudioToolbox                           0x18b756d20 AudioSessionCreateSessionWithIdentifier_Priv + 552
33  AudioSession                           0x189f6d25c avfaudio::SessionConnector::Connect(AVAudioSession*, applesauce::CF::ObjectRef<__CFRunLoop*>, AudioSessionType, NSString*) + 128
34  AudioSession                           0x189f7595c -[AVAudioSession initWithSessionType:identifier:] + 304
35  AudioSession                           0x189f6d900 -[AVAudioSession initWithSessionType:] + 28
36  AudioSession                           0x189f6bcc0 __32+[AVAudioSession sharedInstance]_block_invoke + 72
37  libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
38  libdispatch.dylib                      0x180848f18 _dispatch_once_callout + 32
39  AudioSession                           0x189f6a0b4 +[AVAudioSession sharedInstance] + 156
40  CallKit                                0x1a6761ba8 __42-[CXProvider registerCurrentConfiguration]_block_invoke + 80
41  libdispatch.dylib                      0x180845924 _dispatch_call_block_and_release + 32
42  libdispatch.dylib                      0x180847670 _dispatch_client_callout + 20
43  libdispatch.dylib                      0x18084edf4 _dispatch_lane_serial_drain + 672
44  libdispatch.dylib                      0x18084f968 _dispatch_lane_invoke + 392
45  libdispatch.dylib                      0x18085a1b8 _dispatch_workloop_worker_thread + 656
46  libsystem_pthread.dylib                0x1f1ea70f4 _pthread_wqthread + 288
47  libsystem_pthread.dylib                0x1f1ea6e94 start_wqthread + 8

Thread 7:
0   libsystem_pthread.dylib                0x1f1ea6e8c start_wqthread + 0

Thread 8:
0   libsystem_pthread.dylib                0x1f1ea6e8c start_wqthread + 0

Thread 9 name:  AVAudioSession Notify Thread
Thread 9:
0   libsystem_kernel.dylib                 0x1b826b504 mach_msg_trap + 8
1   libsystem_kernel.dylib                 0x1b826bb9c mach_msg + 76
2   CoreFoundation                         0x180b43738 __CFRunLoopServiceMachPort + 372
3   CoreFoundation                         0x180b47a2c __CFRunLoopRun + 1212
4   CoreFoundation                         0x180b5b468 CFRunLoopRunSpecific + 600
5   AudioSession                           0x189f6e308 CADeprecated::GenericRunLoopThread::Entry(void*) + 164
6   AudioSession                           0x189f77d64 CADeprecated::CAPThread::Entry(CADeprecated::CAPThread*) + 92
7   libsystem_pthread.dylib                0x1f1ea79a4 _pthread_start + 148
8   libsystem_pthread.dylib                0x1f1ea6ea0 thread_start + 8


Thread 0 crashed with ARM Thread State (64-bit):
    x0: 0x0000000000000000   x1: 0x0000000000000000   x2: 0x0000000000000000   x3: 0x0000000000000000
    x4: 0x000000019951b0ad   x5: 0x000000016cf562c0   x6: 0x000000000000006e   x7: 0x0000000000000a00
    x8: 0xdcc6cf154082bb6b   x9: 0xdcc6cf144399beeb  x10: 0x0000000000000002  x11: 0x000000000000000b
   x12: 0x000000009ac20840  x13: 0x000000001ac20800  x14: 0x0000000000000010  x15: 0x0000000000000002
   x16: 0x0000000000000148  x17: 0x00000001031b0580  x18: 0x000000013a10b940  x19: 0x0000000000000006
   x20: 0x0000000000000103  x21: 0x00000001031b0660  x22: 0x0000000282bf02a0  x23: 0x00000001cb4c4a4f
   x24: 0x0000000000000001  x25: 0x00000001deba8d50  x26: 0x00000001b3a55000  x27: 0x000000000000000f
   x28: 0x0000000002ffffff   fp: 0x000000016cf56230   lr: 0x00000001f1ead378
    sp: 0x000000016cf56210   pc: 0x00000001b8271964 cpsr: 0x40001000
   far: 0x00000001d79b1d58  esr: 0x56000080  Address size fault

Binary Images:
       0x1b826a000 -        0x1b829dfff libsystem_kernel.dylib arm64e  <eb3e47f3395335839feefb6cff8a8d7a> /usr/lib/system/libsystem_kernel.dylib
       0x1f1ea6000 -        0x1f1eb1fff libsystem_pthread.dylib arm64e  <c5c27e9d955739c9b9c65f6e7323ee1c> /usr/lib/system/libsystem_pthread.dylib
       0x18ba79000 -        0x18baf7fff libsystem_c.dylib arm64e  <f3afe30409793cba8338bebe9722ecd8> /usr/lib/system/libsystem_c.dylib
       0x199504000 -        0x19951dfff libc++abi.dylib arm64e  <71b1e39fb291315daf46a4343e707387> /usr/lib/libc++abi.dylib
       0x1993fa000 -        0x199433fff libobjc.A.dylib arm64e  <73e920f0e7ce394197d87a10dd2cd390> /usr/lib/libobjc.A.dylib
       0x180843000 -        0x180889fff libdispatch.dylib arm64e  <edd169e1d0db3808a19e99c1cd5a1c4c> /usr/lib/system/libdispatch.dylib
       0x1b3a4f000 -        0x1b3a57fff PushKit arm64e  <9765e782591a3b4e9ab26ed5e69627e8> /System/Library/Frameworks/PushKit.framework/PushKit
       0x180b3c000 -        0x180f8ffff CoreFoundation arm64e  <16faa70c278c3561859ecec407c2dc7c> /System/Library/Frameworks/CoreFoundation.framework/CoreFoundation
       0x19c6e5000 -        0x19c6edfff GraphicsServices arm64e  <064a1bb60e413ad2a402fb563fc141f5> /System/Library/PrivateFrameworks/GraphicsServices.framework/GraphicsServices
       0x182fe3000 -        0x18486dfff UIKitCore arm64e  <cd7f7ba2a2c63727aff69baab60cc6ab> /System/Library/PrivateFrameworks/UIKitCore.framework/UIKitCore
       0x102ea8000 -        0x102fb3fff Doctor arm64  <4377121914133971bb4c82f325b3422e> /private/var/containers/Bundle/Application/80047B71-5198-40B8-B2C8-D9A66282ED40/Doctor.app/Doctor
       0x103144000 -        0x10319bfff dyld arm64e  <f94ccc7a6d1a33c7997ff611a6caa7e0> /usr/lib/dyld
       0x18181a000 -        0x1822e0fff libnetwork.dylib arm64e  <fb6fbf7c88273375a5006d440f277a49> /usr/lib/libnetwork.dylib
       0x18235f000 -        0x182665fff Foundation arm64e  <9618b2f2a4c23e07b7eed8d9e1bdeaec> /System/Library/Frameworks/Foundation.framework/Foundation
       0x1f1ec1000 -        0x1f1ef8fff libxpc.dylib arm64e  <4a0071bc1b1f3cbb960272663b72e875> /usr/lib/system/libxpc.dylib
       0x199d9f000 -        0x199dd2fff libAudioToolboxUtility.dylib arm64e  <670e8c2b1aaf3475a3dc3f64a81c41d0> /usr/lib/libAudioToolboxUtility.dylib
       0x19398a000 -        0x193c29fff AudioToolboxCore arm64e  <816c256e43313d5891ae7033a41f3790> /System/Library/PrivateFrameworks/AudioToolboxCore.framework/AudioToolboxCore
       0x18b5d2000 -        0x18b860fff AudioToolbox arm64e  <9dbb456d92123914a2eaa0a78f8df049> /System/Library/Frameworks/AudioToolbox.framework/AudioToolbox
       0x189f68000 -        0x189f91fff AudioSession arm64e  <8fa06a47169f3f56bc5b2ad366ad8f9e> /System/Library/PrivateFrameworks/AudioSession.framework/AudioSession
       0x1a671e000 -        0x1a679bfff CallKit arm64e  <74e4da77df3f30d09305318a76cfab7e> /System/Library/Frameworks/CallKit.framework/CallKit

EOF

更新:当在Xcode中运行时,我可以看到后台应用程序正在接收推送并尝试管理它,将状态发送回服务器。

REQUEST PARAMETERS ["call_id": "1045"]

随后我立即收到了

2022-02-21 08:52:04.259224+0300 Doctor[679:161536] Apps receving VoIP pushes must post an incoming call (via CallKit or IncomingCallNotifications) in the same run loop as   pushRegistry:didReceiveIncomingPushWithPayload:forType:[withCompletionHandler:] without delay.
2022-02-21 08:52:04.259413+0300 Doctor[679:161536] *** Assertion failure in -[PKPushRegistry _terminateAppIfThereAreUnhandledVoIPPushes], PKPushRegistry.m:353
2022-02-21 08:52:04.259838+0300 Doctor[679:161536] *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'
*** First throw call stack:
(0x19ef6f25c 0x1b2d04480 0x19ee7cc98 0x1a01b4ef8 0x1c715370c 0x10542132c 0x105430520 0x1c715274c 0x10541fae8 0x10542132c 0x10542f76c 0x19eeee298 0x19eee86f8 0x19eee77d0 0x1b5629570 0x1a18142d0 0x1a181984c 0x1049e8f14 0x19ebc6140)
libc++abi: terminating with uncaught exception of type NSException
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Killing app because it never posted an incoming call to the system after receiving a PushKit VoIP push callback.'
terminating with uncaught exception of type NSException

在我的函数pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void)完成之前,发生了一些事情。

当我尝试在其中设置断点以跟踪逻辑时,我立即收到来自调试器的信号9终止。

这可能是由于线程问题导致的吗?我使用异步方式将反馈发送到服务器,所以可能需要太长时间,而在我报告我的调用之前,didReceiveIncomingPushWith payload的执行就已经完成了吗?


你是否在Xcode的“签名和能力”->“后台模式”下启用了Voice over IPBackground fetch - Sreekuttan
你好,Sreekuttan!非常感谢你的回复!是的,VoIP和后台获取都开启了。今天服务器端被切换回沙盒环境,我尝试在调试中检查它(例如从Xcode本身调用正在调试模式下运行的设备),但我发现它失败并显示“来自调试器的消息:由于信号9而终止”,设备日志中也有相同类型的崩溃报告。这并没有给我带来太多帮助 :( - Andrey Lesnykh
有趣的是,在报告调用之前它失败了。例如,我从xcode启动应用程序,在func pushRegistry(_ registry:PKPushRegistry,didReceiveIncomingPushWith payload:PKPushPayload,for type:PKPushType,completion:@escaping() - > Void)的开头设置断点并将其放在后台。它接收到推送,开始调试,立即失败,并显示“来自调试器的消息:由于信号9而终止”,在完成didReceiveIncomingPushWith payload之前,甚至没有机会将报告抛出给CallKit。奇怪0_0 - Andrey Lesnykh
更新:请查看我的帖子,其中包含Xcode的结果/断点未设置? - Andrey Lesnykh
1个回答

2

经过一番努力,我终于找到了问题所在。

问题是:当接收到推送时,我会检查后端是否有效,但这显然是异步的,从后台处理需要太长时间,因此iOS认为我的应用程序“未及时报告呼叫”。

我还不确定如何处理这种情况,但就问题本身而言-确实是由于我的服务器调用引起的。只需将其注释掉就完全解决了问题。

如果您遇到同样的问题,请检查您的PushRegistry didReceiveIncomingPushWith函数代码中是否有使用异步/闭包的任何调用。这可能有助于您解决问题。


您可以使用通用参数(或非验证报告的调用参数等)立即报告呼叫,并在从服务器调用获取正确信息后稍后更新参数。 - chadbag

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接