在 React Native 应用程序中,共享功能是在 ios 本机中实现的。 UIDocumentInteraction 控制器用于显示共享窗口。
下面的代码被编写为 UIBarButton 的操作选择器。
@objc fileprivate func shareTapped(_ sender: UIBarButtonItem) {
if let pageURL = extractPageFromDocument(document, forPageNumber: Int(pageIndex), withName: "share-report-page.pdf") {
documentInteractionController.url = pageURL
documentInteractionController.presentOptionsMenu(from: sender, animated: true)
}
}
当在 xcode 方案中启用调试可执行文件时,代码运行得非常好。
启用调试可执行文件后,此屏幕出现。
在 xcode 中禁用调试可执行文件的情况下运行应用程序时,相同的代码会产生崩溃。崩溃日志如下。
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[SHSheetPresenter applyOptionsOnWillMoveToParentViewController:]: unrecognized selector sent to instance 0x6000038bea00'
*** First throw call stack:
(
0 CoreFoundation 0x0000000114423531 __exceptionPreprocess + 242
1 libobjc.A.dylib 0x0000000110ea37e8 objc_exception_throw + 48
2 CoreFoundation 0x0000000114438643 +[NSObject(NSObject) instanceMethodSignatureForSelector:] + 0
3 CoreFoundation 0x0000000114427cc4 ___forwarding___ + 1459
4 CoreFoundation 0x0000000114429ec8 _CF_forwarding_prep_0 + 120
5 OneViewNew 0x00000001059161b5 -[UIViewController(LayoutProtocol) willMoveToParentViewController:] + 133
6 UIKitCore 0x0000000137be2b6c -[UIViewController _addChildViewController:performHierarchyCheck:notifyWillMove:] + 691
7 UIKitCore 0x0000000137afde44 -[UINavigationController pushViewController:transition:forceImmediate:] + 1782
8 UIKitCore 0x0000000137afd594 -[UINavigationController pushViewController:animated:] + 992
9 ShareSheet 0x000000012ae7fa2a -[SHSheetRouter presentMainViewController:withNavigationControllerSupport:] + 252
10 ShareSheet 0x000000012ae33707 -[SHSheetPresenter prepareViewIfNeeded] + 714
11 ShareSheet 0x000000012ae1a7ca -[UIActivityViewController viewDidLoad] + 110
12 UIKitCore 0x0000000137bd7e1a -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 80
13 UIKitCore 0x0000000137bddf12 -[UIViewController loadViewIfRequired] + 1342
14 UIKitCore 0x0000000137bde2f9 -[UIViewController view] + 27
15 UIKitCore 0x0000000137bf690c -[UIViewController _setPresentationController:] + 92
16 UIKitCore 0x0000000137bee745 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1472
17 UIKitCore 0x0000000137bf20b1 -[UIViewController _presentViewController:withAnimationController:completion:] + 4488
18 CoreFoundation 0x000000011442a15c __invoking___ + 140
19 CoreFoundation 0x0000000114427483 -[NSInvocation invoke] + 302
20 UIKitCore 0x0000000137bebd8e -[UIViewController _endDelayingPresentation] + 441
21 ShareSheet 0x000000012ae1b5f2 -[UIActivityViewController _endDelayingPresentation] + 229
22 ShareSheet 0x000000012ae0a656 -[SHSheetScene scene:didReceiveActions:] + 589
23 FrontBoard 0x000000012d082630 -[FBSceneObserver scene:didReceiveActions:] + 104
24 FrontBoard 0x000000012d080457 __57-[FBSceneWorkspace scene:didReceiveActions:forExtension:]_block_invoke + 1212
25 BaseBoard 0x000000011f19770c -[BSEventQueue _processNextEvent] + 294
26 BaseBoard 0x000000011f197b5d -[BSEventQueue executeOrInsertEvents:atPosition:] + 778
27 BaseBoard 0x000000011f1977fc -[BSEventQueue executeOrInsertEvent:atPosition:] + 112
28 FrontBoard 0x000000012d07c829 -[FBSceneWorkspace _executeNextIdleEventIfAppropriate] + 303
29 FrontBoard 0x000000012d07c6ed -[FBSceneWorkspace _executeEventWhenIdle:] + 98
30 FrontBoard 0x000000012d07fe55 -[FBSceneWorkspace scene:didReceiveActions:forExtension:] + 684
31 libdispatch.dylib 0x0000000114f643ec _dispatch_call_block_and_release + 12
32 libdispatch.dylib 0x0000000114f656d8 _dispatch_client_callout + 8
33 libdispatch.dylib 0x0000000114f7448c _dispatch_main_queue_drain + 1420
34 libdispatch.dylib 0x0000000114f73ef2 _dispatch_main_queue_callback_4CF + 31
35 CoreFoundation 0x000000011437faf4 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 9
36 CoreFoundation 0x000000011437a42f __CFRunLoopRun + 2463
37 CoreFoundation 0x00000001143796ad CFRunLoopRunSpecific + 557
38 GraphicsServices 0x000000011f92e08f GSEventRunModal + 137
39 UIKitCore 0x00000001385c8ad1 -[UIApplication _run] + 972
40 UIKitCore 0x00000001385cd551 UIApplicationMain + 123
41 OneViewNew 0x0000000104d5cf1f main + 63
42 dyld 0x00000001103023e0 start_sim + 10
43 ??? 0x0000000207bf8345 0x0 + 8719926085
)
libc++abi: terminating due to uncaught exception of type NSException
在崩溃之前尝试使用异常断点进行调试,调试器在“UIViewController+LayoutProtocol”的以下位置命中。
(https://i.sstatic.net/QG9FrjnZ.png)
这里的Self.presenter值是:
<SHSheetPresenter: 0x7fa3569125f0>
并且resolveOptions为零。
崩溃可能是由于无法识别的选定错误造成的,当在不支持该方法的对象上调用方法时,这种情况很常见。检查对标准控制器的扩展或修改,并确保所有对象都正确初始化。另外,确认与任何外部库的兼容性。