-->

iOS 9 crash when presenting UIActivityViewControll

2019-08-10 06:51发布

问题:

My app is crashing any time I present a UIActivityViewController, only on iOS9.

I've isolated the code down to this: (Cleared everything from the AppDelegate minus setting my test view controller as the root and only VC).

In the test view controller on button tap: (I made the activityVC an instance property to check if there was a deallocation issue because other debugging efforts suggested that the activityVC might get dealloced during presentation)

NSString *string = @"PLS WORK";

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

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

yields

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 )

Assembler crash log:

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   $0x20100, %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

What is odd is that creating a new project targeted for iOS9 with the exact same code does not crash. I don't know how I can isolate this issue in my project any further. I'd appreciate any hints or debugging suggestions!

回答1:

If you have a category on UIViewController with a property named window, this is the result. This only happens since the release of iOS 9.



回答2:

With the release of iOS 9, Apple introduced a property named window on a UIViewController -- Check the use of your variable names.