试图用未知的演示者解雇UIAlertController

时间:2015-04-15 11:38:56

标签: ios objective-c cocoa-touch uialertview stack-trace

我的应用程序崩溃了,它必须是因为UIAlertController。

只有在UIAlertController可用的iOS 8.x上才会出现此问题。奇怪的是,我的应用程序不使用UIAlertViewController,也不使用UIAlertView

报告告诉我:

Trying to dismiss UIAlertController <UIAlertController: 0x172c5d80> with unknown presenter.

如何发生这种情况?

我想过

  1. 通过摇动手势撤消系统警报视图
  2. 在屏幕上仍显示提示或通用对话框时取消分配WebView
  3. 电池电量不足警报
  4. 但是没有一个案例让我陷入崩溃。

    崩溃日志告诉我的是,操作系统显示了一个AlertView,它将附加到我的应用程序窗口,并且在某些情况下会松开呈现UIAlertViewController的父视图控制器。

    任何想法如何找到问题?

    此处是堆栈跟踪

    _________________________________
    0    CoreFoundation                         0x2bc0c45f __exceptionPreprocess + 127
    1    libobjc.A.dylib                        0x39c79c8b objc_exception_throw + 36
    2    CoreFoundation                         0x2bc0c3a5 +[NSException raise:format:] + 110
    3    UIKit                                  0x2f4ad13d -[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 414
    4    UIKit                                  0x2f4acf97 -[UIAlertController _dismissAnimated:triggeringAction:] + 28
    5    UIKit                                  0x2f590a0b -[_UIAlertControllerActionView touchesEnded:withEvent:] + 160
    6    UIKit                                  0x2f159567 -[UIWindow _sendTouchesForEvent:] + 520
    7    UIKit                                  0x2f152e31 -[UIWindow sendEvent:] + 542
    8    UIKit                                  0x2f129759 -[UIApplication sendEvent:] + 194
    9    UIKit                                  0x2f39d2f9 _UIApplicationHandleEventFromQueueEvent + 14166
    10   UIKit                                  0x2f1281a9 _UIApplicationHandleEventQueue + 1350
    11   CoreFoundation                         0x2bbd2fbf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 12
    12   CoreFoundation                         0x2bbd23cf __CFRunLoopDoSources0 + 216
    13   CoreFoundation                         0x2bbd0a35 __CFRunLoopRun + 770
    14   CoreFoundation                         0x2bb1e3b1 CFRunLoopRunSpecific + 474
    15   CoreFoundation                         0x2bb1e1c3 CFRunLoopRunInMode + 104
    16   GraphicsServices                       0x3308d201 GSEventRunModal + 134
    17   UIKit                                  0x2f18843d UIApplicationMain + 1438
    18   MyApp                                  0x00028a07 main (main.mm:16)
    

    修改

    漏洞询问我的窗口初始化。这是我的AppDelegate的代码

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        self.window = [[MyAppCustomWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    
        _mainViewController = [[MyAppContainerViewController alloc] initWithNibName:nil bundle:nil];
        _mainStatusBarVC = [[MyAppStatusBarVC alloc] initWithRootVC:_mainViewController];
    
        [self.window setRootViewController:_mainStatusBarVC];
        [self.window makeKeyAndVisible];
    
        return YES;
    }
    

3 个答案:

答案 0 :(得分:2)

我打赌你的崩溃发生在iPad上。

在iPad上,从iOS8开始,UIActionSheet似乎是用View

处理的

使用此代码,

SeekBar

我的应用程序崩溃了,你得到了同样的错误 为了防止这种情况,我只是在下一次MainThread执行时调度复杂的dismiss调用,以便为隐藏的UIAlertController提供正确释放的机会。

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    if(buttonIndex == 1) return; // Cancel button

    [self doSomeViewControllerDismisses];
}

答案 1 :(得分:1)

此表单的堆栈跟踪通常表示您已从UIViewController导航,而您出现的警报仍在解除。

对此的一般补救措施是在UIAlertViewDelegate的alertView:didDismissWithButtonIndex:方法中显示或解除控制器,从那时起您就确定演示者在解雇期间不会消失。

在您的情况下,如果您找不到任何可重现的案例,您可以在呈现/解除控制器之前尝试检查presentViewController,看看是否会出现任何问题。

但是,如果您审核控制器转换,您可能会发现响应系统警报的某个地方可以通过编程方式触发导航。您是否有任何功能可以引发系统警报以进行用户授权,例如访问照片或其他任何内容,并且拒绝它会导致控制器以编程方式被您的错误处理解雇?这似乎是一个相当合理的情况。

答案 2 :(得分:0)

尝试使用主thrad上的Block关闭主线程Alertview。

dispatch_async(dispatch_get_main_queue(), { () -> Void in
  //  Write your alert view code in swift language .
})