Application being hang when use UIActivityViewController

Our application uses UIActivityViewController to share files, and we have received numerous complaints from users stating that triggering the share functionality causes the app to hang, making it unresponsive. Users are instructed to restart their devices, after which the sharing function works normally.

0   libsystem_kernel.dylib              0x00000001daae2708 mach_msg2_trap + 8
1   libsystem_kernel.dylib              0x00000001daae5e18 mach_msg2_internal + 80
2   libsystem_kernel.dylib              0x00000001daae5d30 mach_msg_overwrite + 424
3   libsystem_kernel.dylib              0x00000001daae5b7c mach_msg + 24
4   libdispatch.dylib                   0x00000001926d1f14 _dispatch_mach_send_and_wait_for_reply + 544
5   libdispatch.dylib                   0x00000001926d22b4 dispatch_mach_send_with_result_and_wait_for_reply + 60
6   libxpc.dylib                        0x0000000211c1b84c xpc_connection_send_message_with_reply_sync + 256
7   Foundation                          0x00000001891e98d8 __NSXPCCONNECTION_IS_WAITING_FOR_A_SYNCHRONOUS_REPLY__ + 16
8   Foundation                          0x00000001891e6034 -[NSXPCConnection _sendInvocation:orArguments:count:methodSignature:selector:withProxy:] + 2160
9   Foundation                          0x000000018924fda4 -[NSXPCConnection _sendSelector:withProxy:arg1:] + 116
10  Foundation                          0x000000018924fa18 _NSXPCDistantObjectSimpleMessageSend1 + 60
11  ShareSheet                          0x00000001a89e7b2c -[SFShareSheetSlotManager ensureConnectionEstablished] + 220
12  ShareSheet                          0x00000001a89e7960 -[SFShareSheetSlotManager ensureXPCStarted] + 440
13  ShareSheet                          0x00000001a89e7f90 -[SFShareSheetSlotManager activate] + 188
14  ShareSheet                          0x00000001a8a0020c -[SHSheetServiceManager init] + 100
15  ShareSheet                          0x00000001a89f347c -[SHSheetInteractor _setupServiceManagerIfNeeded] + 52
16  ShareSheet                          0x00000001a89f1998 -[SHSheetInteractor initWithContext:] + 76
17  ShareSheet                          0x00000001a89dd450 +[SHSheetFactory createMainPresenterWithContext:] + 204
18  ShareSheet                          0x00000001a89d3e90 -[UIActivityViewController _createMainPresenterIfNeeded] + 84
19  ShareSheet                          0x00000001a89d53c4 -[UIActivityViewController _viewControllerPresentationDidInitiate] + 104
20  UIKitCore                           0x000000018d247fd0 -[UIViewController _presentViewController:withAnimationController:completion:] + 220
21  UIKitCore                           0x000000018d24a71c __63-[UIViewController _presentViewController:animated:completion:]_block_invoke + 88
22  UIKitCore                           0x000000018d244ad0 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 532
23  UIKitCore                           0x000000018d2447c0 -[UIViewController _presentViewController:animated:completion:] + 324
24  UIKitCore                           0x000000018d2445cc -[UIViewController presentViewController:animated:completion:] + 164

Above is the stack trace when the hang occurs. We found that UIActivityViewController ultimately calls xpc_connection_send_message_with_reply_sync, which synchronously waits for messages on the main thread, leading to the hang.

Are there any suggestions that can avoid this waiting forever hang?

I would need to see the complete symbolicated Apple crash report. Could you add the complete crash report as an attachment. Posting a Crash Report explains how to do so.

I've attached the full crash report generated by Metric, thanks for your help!

Application being hang when use UIActivityViewController
 
 
Q