iOS 9 呈现 UIActivityViewController 时崩溃:[UIView _fromWindowOrientation] 无法识别的选择器发送到实例 (UIView)

iOS 9 crash when presenting UIActivityViewController : [UIView _fromWindowOrientation] unrecognized selector sent to instance (UIView)

每当我显示 UIActivityViewController 时,我的应用程序都会崩溃,仅在 iOS9。

我已将代码隔离为:(清除了 AppDelegate 中的所有内容减去将我的测试视图控制器设置为根并且仅 VC)。

在点击按钮的测试视图控制器中: (我将 activityVC 设为实例 属性 以检查是否存在释放问题,因为其他调试工作表明 activityVC 可能在演示期间被释放)

NSString *string = @"PLS WORK";

self.activityViewController =
[[UIActivityViewController alloc] initWithActivityItems:@[string]
                                  applicationActivities:nil];

[self presentViewController:self.activityViewController
                   animated:YES
                 completion:nil];

产量

2015-09-21 11:41:55.889 App[21548:606985] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView
_fromWindowOrientation]: unrecognized selector sent to instance 0x7f9168f25760'
*** First throw call stack: (   0   CoreFoundation                      0x000000010c68df65 __exceptionPreprocess + 165  1   libobjc.A.dylib    0x000000010be08deb objc_exception_throw + 48     2   CoreFoundation       0x000000010c69658d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205   3   CoreFoundation                      0x000000010c5e3f7a
___forwarding___ + 970  4   CoreFoundation                      0x000000010c5e3b28 _CF_forwarding_prep_0 + 120  5   UIKit              0x000000010b104aa0 -[_UIViewControllerTransitionContext
_affineTransform] + 132     6   UIKit                               0x000000010b104c77 -[_UIViewControllerTransitionContext targetTransform] + 29   7   UIKit                               0x000000010b10895f -[_UIViewControllerTransitionCoordinator targetTransform] + 40   8   UIKit                               0x000000010b109483 _UIViewControllerTransitionCoordinatorIsRotating + 35    9   UIKit                               0x000000010a8fbcba
-[UIViewController viewWillTransitionToSize:withTransitionCoordinator:] + 78    10  UIKit   0x000000010aa5e68d __79-[UIAlertController
_contentViewControllerWillTransitionToSize:withAnimations:]_block_invoke591
+ 154   11  UIKit                               0x000000010a7faeec +[UIView(Animation) performWithoutAnimation:] + 65   12  UIKit                               0x000000010b03b693 -[_UIAnimationCoordinator animate] + 128     13  UIKit 0x000000010aa5e54d -[UIAlertController
_contentViewControllerWillTransitionToSize:withAnimations:] + 1071  14  UIKit                               0x000000010b0d2910
-[_UIAlertControllerView _sizeOfContentViewControllerChanged] + 1009    15  UIKit                               0x000000010aa5afe8
-[UIAlertController viewDidLoad] + 659  16  UIKit                               0x000000010a8e0931 -[UIViewController loadViewIfRequired] + 1344    17  UIKit                               0x000000010a8e0c7d
-[UIViewController view] + 27   18  UIKit                               0x000000010b0292ab -[UIActivityViewController viewDidLoad] + 1266   19  UIKit                               0x000000010a8e0931
-[UIViewController loadViewIfRequired] + 1344   20  UIKit                               0x000000010a8e0c7d -[UIViewController view] + 27    21  UIKit            0x000000010a8fa738 -[UIViewController _setPresentationController:] + 100   22  UIKit                               0x000000010a8f1cf4
-[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:]
+ 1437  23  UIKit                               0x000000010a8f3970 -[UIViewController _presentViewController:withAnimationController:completion:] + 4870    24  UIKit                               0x000000010a8f6878
-[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 489     25  UIKit                               0x000000010a8f6387
-[UIViewController presentViewController:animated:completion:] + 179    26  App                             0x0000000107607734
-[YYWTFViewController wtfButtonPressed:] + 644  27  UIKit                               0x000000010a7571fa -[UIApplication sendAction:to:from:forEvent:] + 92   28  UIKit                               0x000000010a8bb504
-[UIControl sendAction:to:forEvent:] + 67   29  UIKit                               0x000000010a8bb7d0 -[UIControl _sendActionsForEvents:withEvent:] + 311  30  UIKit                               0x000000010a8ba906
-[UIControl touchesEnded:withEvent:] + 601  31  UIKit                               0x000000010a7c1aa3 -[UIWindow _sendTouchesForEvent:] + 835  32  UIKit  0x000000010a7c2691 -[UIWindow sendEvent:] + 865  33  UIKit             0x000000010a774752 -[UIApplication sendEvent:] + 263  34  UIKit        0x000000010a74ffcc _UIApplicationHandleEventQueue + 6693   35  CoreFoundation                      0x000000010c5ba0a1
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17     36  CoreFoundation                      0x000000010c5affcc
__CFRunLoopDoSources0 + 556     37  CoreFoundation                      0x000000010c5af483 __CFRunLoopRun + 867     38  CoreFoundation            0x000000010c5aee98 CFRunLoopRunSpecific + 488     39  GraphicsServices    0x000000010f0d9ad2 GSEventRunModal + 161    40  UIKit                    0x000000010a755676 UIApplicationMain + 171     41  App                    0x000000010766101f main + 111    42  libdyld.dylib                       0x000000010d98792d start + 1 )

汇编程序崩溃日志:

0x10a7555cb <+0>:   pushq  %rbp
0x10a7555cc <+1>:   movq   %rsp, %rbp
0x10a7555cf <+4>:   pushq  %r15
0x10a7555d1 <+6>:   pushq  %r14
0x10a7555d3 <+8>:   pushq  %r13
0x10a7555d5 <+10>:  pushq  %r12
0x10a7555d7 <+12>:  pushq  %rbx
0x10a7555d8 <+13>:  pushq  %rax
0x10a7555d9 <+14>:  movq   %rcx, %rbx
0x10a7555dc <+17>:  movq   %rsi, %r15
0x10a7555df <+20>:  movl   %edi, %r12d
0x10a7555e2 <+23>:  movq   0xcc7ba7(%rip), %r13      ; (void *)0x000000010be1bd00: objc_retain
0x10a7555e9 <+30>:  movq   %rdx, %rdi
0x10a7555ec <+33>:  callq  *%r13
0x10a7555ef <+36>:  movq   %rax, %r14
0x10a7555f2 <+39>:  movq   %rbx, %rdi
0x10a7555f5 <+42>:  callq  *%r13
0x10a7555f8 <+45>:  movq   %rax, %r13
0x10a7555fb <+48>:  leaq   0xcc5aea(%rip), %rbx      ; _UIApplicationLinkedOnVersion
0x10a755602 <+55>:  movl   (%rbx), %eax
0x10a755604 <+57>:  testl  %eax, %eax
0x10a755606 <+59>:  jne    0x10a755627               ; <+92>
0x10a755608 <+61>:  cmpq   $-0x1, 0xcc18a0(%rip)     ; WebKitSetIsClassic + 7
0x10a755610 <+69>:  je     0x10a755651               ; <+134>
0x10a755612 <+71>:  leaq   0xcc1897(%rip), %rdi      ; _UIApplicationLinkedOnVersionOnce
0x10a755619 <+78>:  leaq   0xccaeb0(%rip), %rsi      ; __block_literal_global1457
0x10a755620 <+85>:  callq  0x10b1a3f5c               ; symbol stub for: dispatch_once
0x10a755625 <+90>:  movl   (%rbx), %eax
0x10a755627 <+92>:  cmpl   [=13=]x20100, %eax
0x10a75562c <+97>:  jb     0x10a755651               ; <+134>
0x10a75562e <+99>:  callq  0x10b1a3746               ; symbol stub for: objc_autoreleasePoolPush
0x10a755633 <+104>: movq   %rax, %rbx
0x10a755636 <+107>: movl   %r12d, %edi
0x10a755639 <+110>: movq   %r15, %rsi
0x10a75563c <+113>: movq   %r14, %rdx
0x10a75563f <+116>: movq   %r13, %rcx
0x10a755642 <+119>: callq  0x10a755698               ; _UIApplicationMainPreparations
0x10a755647 <+124>: movq   %rbx, %rdi
0x10a75564a <+127>: callq  0x10b1a3740               ; symbol stub for: objc_autoreleasePoolPop
0x10a75564f <+132>: jmp    0x10a755662               ; <+151>
0x10a755651 <+134>: movl   %r12d, %edi
0x10a755654 <+137>: movq   %r15, %rsi
0x10a755657 <+140>: movq   %r14, %rdx
0x10a75565a <+143>: movq   %r13, %rcx
0x10a75565d <+146>: callq  0x10a755698               ; _UIApplicationMainPreparations
0x10a755662 <+151>: movq   0xcc59df(%rip), %rdi      ; UIApp
0x10a755669 <+158>: movq   0xc4a3c8(%rip), %rsi      ; "_run"
0x10a755670 <+165>: callq  *0xcc7b0a(%rip)           ; (void *)0x000000010be1e800: objc_msgSend
0x10a755676 <+171>: movq   0xcc7b0b(%rip), %rbx      ; (void *)0x000000010be1bd70: objc_release <--- DEAD

奇怪的是,使用完全相同的代码创建针对 iOS9 的新项目不会崩溃。我不知道如何在我的项目中进一步隔离这个问题。如果有任何提示或调试建议,我将不胜感激!

如果您在 UIViewController 上有一个类别 属性 名为 window,这就是结果。这仅在 iOS 9.

发布后才会发生

随着 iOS 9 的发布,Apple 在 UIViewController 上引入了一个名为 window 的 属性 -- 检查你的使用情况变量名。