崩溃viewDidMoveToWindow:shouldAppearOrDisappear:在iOS 10上

时间:2017-02-16 09:32:19

标签: ios objective-c

一段时间以来我的应用程序在生产中崩溃但是在调试模式下无法重现此错误。

Crashlytics中的错误是:

UIKit
-[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:]

SIGABRT ABORT 0x00000001825d4d74

    Crashed: com.apple.main-thread
    0  libsystem_kernel.dylib         0x1825d4d74 __abort_with_payload + 8
    1  libsystem_kernel.dylib         0x1825d1480 abort_with_payload_wrapper_internal + 100
    2  libsystem_kernel.dylib         0x1825d141c abort_with_payload_wrapper_internal + 34
    3  libobjc.A.dylib                0x18203fed8 _objc_fatalv(unsigned long long, unsigned long long, char const*, char*) + 112
    4  libobjc.A.dylib                0x18203fe30 __objc_error + 42
    5  libobjc.A.dylib                0x182052cd4 weak_entry_insert(weak_table_t*, weak_entry_t*) + 318
    6  libobjc.A.dylib                0x182058664 objc_initWeak + 324
    7  UIKit                          0x1894ce1bc -[UIViewController viewDidMoveToWindow:shouldAppearOrDisappear:] + 2068
    8  UIKit                          0x18944db5c -[UIView(Internal) _didMoveFromWindow:toWindow:] + 1352
    9  UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    10 UIKit                          0x189471714 -[UIScrollView _didMoveFromWindow:toWindow:] + 92
    11 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    12 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    13 UIKit                          0x189471714 -[UIScrollView _didMoveFromWindow:toWindow:] + 92
    14 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    15 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    16 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    17 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    18 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    19 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    20 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    21 UIKit                          0x18944d8e4 -[UIView(Internal) _didMoveFromWindow:toWindow:] + 720
    22 UIKit                          0x18944cd90 __45-[UIView(Hierarchy) _postMovedFromSuperview:]_block_invoke + 156
    23 Foundation                     0x184034510 -[NSISEngine withBehaviors:performModifications:] + 168
    24 UIKit                          0x18944cc04 -[UIView(Hierarchy) _postMovedFromSuperview:] + 820
    25 UIKit                          0x18974a078 __UIViewWasRemovedFromSuperview + 172
    26 UIKit                          0x18944bc80 -[UIView(Hierarchy) removeFromSuperview] + 512
    27 UIKit                          0x1897a23dc __71-[UIPresentationController _initViewHierarchyForPresentationSuperview:]_block_invoke.629 + 1044
    28 UIKit                          0x18979c4fc -[UIPresentationController transitionDidFinish:] + 124
    29 UIKit                          0x18990afc8 -[_UICurrentContextPresentationController transitionDidFinish:] + 40
    30 UIKit                          0x1897a012c __56-[UIPresentationController runTransitionForCurrentState]_block_invoke_2 + 188
    31 UIKit                          0x189578ad4 -[_UIViewControllerTransitionContext completeTransition:] + 116
    32 UIKit                          0x1895788c0 -[UITransitionView notifyDidCompleteTransition:] + 252
    33 UIKit                          0x1895783dc -[UITransitionView _didCompleteTransition:] + 1240
    34 UIKit                          0x189577ef0 -[UITransitionView _transitionDidStop:finished:] + 124
    35 UIKit                          0x189489b48 -[UIViewAnimationState sendDelegateAnimationDidStop:finished:] + 312
    36 UIKit                          0x189489988 -[UIViewAnimationState animationDidStop:finished:] + 160
    37 QuartzCore                     0x186912404 CA::Layer::run_animation_callbacks(void*) + 260
    38 libdispatch.dylib              0x1824911c0 _dispatch_client_callout + 16
    39 libdispatch.dylib              0x182495d6c _dispatch_main_queue_callback_4CF + 1000
    40 CoreFoundation                 0x1835b5f2c __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12
    41 CoreFoundation                 0x1835b3b18 __CFRunLoopRun + 1660
    42 CoreFoundation                 0x1834e2048 CFRunLoopRunSpecific + 444
    43 GraphicsServices               0x184f65198 GSEventRunModal + 180
    44 UIKit                          0x1894bc628 -[UIApplication _run] + 684
    45 UIKit                          0x1894b7360 UIApplicationMain + 208
    46 <App Name>                     0x100081590 main (main.m:14)
    47 libdispatch.dylib              0x1824c45b8 (Missing)

大多数日志显示用户有1%到3%的RAM内存可用,但有些内存超过10%。

此外,我的应用程序使用Sentry跟踪错误,但此错误不在Sentry中仅在Fabric中。

我的大多数用户都使用iOS 10,但仍然有人使用iOS 9,这种崩溃似乎不会影响这些用户。所以它似乎与iOS 10有关。

我也在这里搜索过但我找不到解决方案甚至是线索。有人可以帮我找到线索吗?

修改

关于注释,新代码介绍它与UIViewController相关的是:

    - (IBAction)tapClose:(id)sender {
        [self close];
    }

    - (void)close {
        _dismissing = YES;

        CGFloat height = self.view.superview.frame.size.height;
        [UIView animateWithDuration:0.2 animations:^{
            [self.view setFrame:CGRectMake(0, height, self.view.frame.size.width, self.view.frame.size.height)];
            _overlay.alpha = 0;
        }                completion:^(BOOL finished) {
            if (finished) {
                [self.view removeFromSuperview];
                [_overlay removeFromSuperview];
                if (self.blockWhenClose) {
                    self.blockWhenClose();
                }
            }
        }];
    }

    - (void)showIn:(UIViewController *)viewcontroller {
        CGRect frame = viewcontroller.view.frame;
        CGFloat height = [self calculateHeight:frame.size.height / 2];
        [self.view setFrame:CGRectMake(0, frame.size.height, frame.size.width, height)];
        [_overlay setFrame:frame];
        _overlay.alpha = 0;
        [viewcontroller addChildViewController:self];
        [viewcontroller.view addSubview:_overlay];
        [viewcontroller.view addSubview:self.view];
        [self didMoveToParentViewController:viewcontroller];
        [UIView animateWithDuration:_duration animations:^{
            _overlay.alpha = 1;
            [self.view setFrame:CGRectMake(0, frame.size.height - height, frame.size.width, height)];
        }];
        _show = YES;
    }

但我不知道崩溃究竟发生在哪里。

1 个答案:

答案 0 :(得分:0)

对我来说,这是从 iOS 14 开始的

问题是,我在代码中将控制器 (A) 的视图作为子视图添加到另一个控制器 (B) 中,而没有持有对控制器 (A) 本身的引用。控制器(A)被释放,下次视图即将出现或消失时,它会尝试通知导致崩溃的控制器(A)。

解决方案:

  • 手动保存对控制器的引用
  • 或 addChildViewController 为您执行上述操作