显示 UIAlertView 时崩溃

Posted

技术标签:

【中文标题】显示 UIAlertView 时崩溃【英文标题】:Crashed When show UIAlertView 【发布时间】:2015-04-07 08:43:31 【问题描述】:

我收到了崩溃日志。似乎当显示 UIAlertView 时,我的应用程序崩溃了,我是工作表,崩溃日志是这样的

Exception Type:  SIGABRT
Exception Codes: #0 at 0x30288dfc
Crashed Thread:  0

Thread 0 Crashed:
0   libsystem_kernel.dylib              0x30288dfc __pthread_kill (in libsystem_kernel.dylib) + 8
1   libsystem_c.dylib                   0x30228909 abort (in libsystem_c.dylib) + 77
2   libsystem_malloc.dylib              0x302b2331 szone_size (in libsystem_malloc.dylib) + 1
3   CoreUI                              0x2811a0b7 _freeBOMFile (in CoreUI) + 35
4   CoreUI                              0x28119da5 BOMFileNewFromFDWithSys (in CoreUI) + 245
5   CoreUI                              0x280c8c95 _BOMFileNewFromCFReadStreamSys (in CoreUI) + 25
6   CoreUI                              0x280fe6b5 __69-[_CSIRenditionBlockData expandCSIBitmapData:fromSlice:makeReadOnly:]_block_invoke (in CoreUI) + 137
7   CoreUI                              0x280fe4a7 -[_CSIRenditionBlockData expandCSIBitmapData:fromSlice:makeReadOnly:] (in CoreUI) + 391
8   CoreUI                              0x28102287 csiCompressImageProviderCopyImageBlockSetWithOptions (in CoreUI) + 1107
9   CoreGraphics                        0x22763423 CGImageProviderCopyImageBlockSetWithOptions (in CoreGraphics) + 179
10  CoreGraphics                        0x227630db img_blocks_create (in CoreGraphics) + 371
11  CoreGraphics                        0x227560a5 img_data_lock (in CoreGraphics) + 1229
12  CoreGraphics                        0x227553bb CGSImageDataLock (in CoreGraphics) + 95
13  libRIP.A.dylib                      0x22ab27b7 ripc_AcquireImage (in libRIP.A.dylib) + 623
14  libRIP.A.dylib                      0x22ab18df ripc_DrawImage (in libRIP.A.dylib) + 611
15  CoreGraphics                        0x227552c1 CGContextDelegateDrawImage (in CoreGraphics) + 45
16  CoreGraphics                        0x22755159 CGContextDrawImage (in CoreGraphics) + 269
17  UIKit                               0x259d1453 -[UIImage drawInRect:blendMode:alpha:] (in UIKit) + 1467
18  UIKit                               0x259d0e87 -[UIImage drawAtPoint:blendMode:alpha:] (in UIKit) + 99
19  UIKit                               0x25a2fdf3 -[UIImage drawAtPoint:] (in UIKit) + 39
20  UIKit                               0x259cf41b -[UIImageView _setImageViewContents:] (in UIKit) + 1179
21  UIKit                               0x259ceaf5 +[UIView(Animation) performWithoutAnimation:] (in UIKit) + 73
22  UIKit                               0x25cc0a69 -[UIImageView _updateImageViewForOldImage:newImage:] (in UIKit) + 677
23  UIKit                               0x259ce507 -[UIImageView setImage:] (in UIKit) + 267
24  UIKit                               0x25e254d5 -[_UIAlertControllerActionView initWithFrame:] (in UIKit) + 605
25  UIKit                               0x259df275 -[UIView init] (in UIKit) + 45
26  UIKit                               0x26065c27 -[_UIAlertControllerView _prepareCancelView] (in UIKit) + 67
27  UIKit                               0x260653c7 -[_UIAlertControllerView _prepareViewsAndAddConstraints] (in UIKit) + 151
28  UIKit                               0x25d42047 -[UIAlertController loadView] (in UIKit) + 75
29  UIKit                               0x259c1f19 -[UIViewController loadViewIfRequired] (in UIKit) + 69
30  UIKit                               0x259c1e9d -[UIViewController view] (in UIKit) + 25
31  UIKit                               0x25ca7149 -[UIViewController _setPresentationController:] (in UIKit) + 93
32  UIKit                               0x25ca2683 -[UIViewController _presentViewController:presentationController:animationController:interactionController:completion:] (in UIKit) + 767
33  UIKit                               0x25ca364f -[UIViewController _presentViewController:withAnimationController:completion:] (in UIKit) + 2851
34  UIKit                               0x25ca515b __62-[UIViewController presentViewController:animated:completion:]_block_invoke (in UIKit) + 259
35  UIKit                               0x25aa1d93 -[UIViewController presentViewController:animated:completion:] (in UIKit) + 195
36  UIKit                               0x2605fb9f -[_UIAlertControllerShimPresenterWindow presentAlertController:animated:completionBlock:] (in UIKit) + 335
37  UIKit                               0x2605e757 -[_UIAlertControllerShimPresenter _presentAlertControllerAnimated:completion:] (in UIKit) + 191
38  UIKit                               0x25d49377 -[UIAlertView _showAnimated:] (in UIKit) + 207
39  MyApp                             0x00ff1a8b +[UIAlertView(Blocks) showConfirmationDialogWithTitle:message:cancel:confirm:handler:] (in MyApp) (UIAlertView+Blocks.m:140)
40  MyApp                             0x000d8fdb -[MyAppViewController startUpdatingLocation] (in MyApp) (MyAppViewController.m:842)
41  MyApp                             0x000d56f1 -[MyAppViewController viewDidAppear:] (in MyApp) (MyAppViewController.m:140)
42  UIKit                               0x259d789f -[UIViewController _setViewAppearState:isAnimating:] (in UIKit) + 503
43  UIKit                               0x25a841b7 -[UINavigationController viewDidAppear:] (in UIKit) + 175
44  UIKit                               0x259d789f -[UIViewController _setViewAppearState:isAnimating:] (in UIKit) + 503
45  UIKit                               0x259d7d63 -[UIViewController _endAppearanceTransition:] (in UIKit) + 291
46  UIKit                               0x25cbd005 __97-[UITabBarController transitionFromViewController:toViewController:transition:shouldSetSelected:]_block_invoke749 (in UIKit) + 25
47  UIKit                               0x25a3bd7f -[UIViewController _executeAfterAppearanceBlock] (in UIKit) + 55
48  UIKit                               0x25a3bd0d _applyBlockToCFArrayCopiedToStack (in UIKit) + 309
49  UIKit                               0x259b7c67 _afterCACommitHandler (in UIKit) + 487
50  CoreFoundation                      0x224ea5cd __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ (in CoreFoundation) + 21
51  CoreFoundation                      0x224e7c8b __CFRunLoopDoObservers (in CoreFoundation) + 279
52  CoreFoundation                      0x224e8093 __CFRunLoopRun (in CoreFoundation) + 915
53  CoreFoundation                      0x22436621 CFRunLoopRunSpecific (in CoreFoundation) + 477
54  CoreFoundation                      0x22436433 CFRunLoopRunInMode (in CoreFoundation) + 107
55  GraphicsServices                    0x2979f0a9 GSEventRunModal (in GraphicsServices) + 137
56  UIKit                               0x25a21359 UIApplicationMain (in UIKit) + 1441
57  MyApp                             0x00011f1f main (in MyApp) (main.m:26)

我尝试模拟内存不足的情况,它仍然是有效的。你有什么想法吗?

【问题讨论】:

如果不显示完整的日志和相关源代码,将很难发现问题。 添加你的代码,没有那个不能说什么问题 抱歉,系统不大,要粘贴的代码太多了。 我也面临同样的问题。您找到解决此崩溃的任何方法了吗? 【参考方案1】:
-(void)addAlertView

    UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:
    @"Title" message:@"This is a test alert" delegate:self 
    cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];

    [alertView show];

  

希望对你有所帮助..

根据你的需要设置消息和按钮

如果它不起作用,则从模拟器中删除你的应用程序并运行

【讨论】:

谢谢,但这对我没有帮助。如果你给alertView设置了一个delegate,你必须小心它,避免发送msg到释放的对象。【参考方案2】:

我得到了相同的崩溃日志,该日志主要是在运行 ios 7.0.4 的设备上找到的。 iOS 8.3之前的版本也有这个问题。

查看代码后发现使用AlertView的类没有声明UIAlterViewDelegate协议。 OC Runtime可以保证delegate方法正常运行,但我认为iOS中存在一些未知逻辑。

修复bug后,崩溃日志消失了....

我认为这是 iOS 8.3 中已修复的 iOS 错误

【讨论】:

以上是关于显示 UIAlertView 时崩溃的主要内容,如果未能解决你的问题,请参考以下文章

UIAlert 需要几秒钟才能显示

在 AFHTTPRequestOperation 失败时显示 UIAlertView

Swift 3.0 中的 UIAlertAction 内的 UIAlertView ?

UIAlertView 用 OK 显示信息性语句

关于 UIAlert 跳转到一个 xib

应用程序在 [UIAlertView 显示] 上崩溃