This application is modifying the autolayout engine from a background thread, which can lead to engi

ios程序运行后,异步访问了一个网络请求。

然后在解析了从服务器返回的信息后,直接new了UIAlertView对象,准备弹窗提示,这时候控制台打印了一串异常的信息:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.

下面还有一串好长的日志:

This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.
 Stack:(
    0   CoreFoundation                      0x004eda84 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x041d8e02 objc_exception_throw + 50
    2   CoreFoundation                      0x004ed9ad +[NSException raise:format:] + 141
    3   Foundation                          0x02b0974b _AssertAutolayoutOnMainThreadOnly + 96
    4   Foundation                          0x02931f49 -[NSISEngine withBehaviors:performModifications:] + 26
    5   Foundation                          0x029354a4 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
    6   UIKit                               0x01256d98 -[UIView(UIConstraintBasedLayout) _calculatedSystemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:hasIntentionallyCollapsedHeight:] + 1194
    7   UIKit                               0x012587e9 -[UIView(AdditionalLayoutSupport) _systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:hasIntentionallyCollapsedHeight:] + 972
    8   UIKit                               0x01258343 -[UIView(UIConstraintBasedLayout) systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:] + 127
    9   UIKit                               0x0125838f -[UIView(UIConstraintBasedLayout) systemLayoutSizeFittingSize:] + 71
    10  UIKit                               0x0137b017 -[_UIAlertControllerView _minimumSizeForAllActions] + 589
    11  UIKit                               0x0137789b -[_UIAlertControllerView _itemSizeForHorizontalLayout:] + 451
    12  UIKit                               0x01377acf -[_UIAlertControllerView _canLayOutActionsHorizontally] + 108
    13  UIKit                               0x01377ff7 -[_UIAlertControllerView _actionLayoutDirectionChanged] + 42
    14  UIKit                               0x0137d13a -[_UIAlertControllerView _updateBackdrop] + 577
    15  UIKit                               0x0137bf85 -[_UIAlertControllerView _updateStyleForIdiomChange:] + 156
    16  UIKit                               0x0137beb1 -[_UIAlertControllerView _setVisualStyle:] + 296
    17  UIKit                               0x00bfebdd -[UIAlertController _updateProvidedStyleWithTraitCollection:] + 525
    18  UIKit                               0x00bfecd1 -[UIAlertController _updateProvidedStyle] + 68
    19  UIKit                               0x00bfee39 -[UIAlertController _resolvedStyleChanged] + 35
    20  UIKit                               0x00bfe30a -[UIAlertController viewDidLoad] + 98
    21  UIKit                               0x00a42a86 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
    22  UIKit                               0x00a475a6 -[UIViewController loadViewIfRequired] + 1384
    23  UIKit                               0x00a479c5 -[UIViewController view] + 35
    24  UIKit                               0x00a63ba2 -[UIViewController _setPresentationController:] + 117
    25  UIKit                               0x00a5a1c6 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1503
    26  UIKit                               0x00a5c143 -[UIViewController _presentViewController:withAnimationController:completion:] + 5297
    27  UIKit                               0x00a5f34b __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 397
    28  UIKit                               0x00a5f690 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 493
    29  UIKit                               0x00a5f177 -[UIViewController presentViewController:animated:completion:] + 182
    30  UIKit                               0x013667ff -[_UIAlertControllerShimPresenterWindow presentAlertController:animated:completionBlock:] + 580
    31  UIKit                               0x01364912 -[_UIAlertControllerShimPresenter _presentAlertControllerAnimated:completion:] + 235
    32  UIKit                               0x00c11990 -[UIAlertView _showAnimated:] + 276
    33  UIKit                               0x00c11b76 -[UIAlertView show] + 41
    34  心动爱                           0x0012997a __37-[MainViewController checkAppVersion]_block_invoke + 762
    35  CFNetwork                           0x03692b62 __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 177
    36  Foundation                          0x029e4a6b __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    37  Foundation                          0x029088ff -[NSBlockOperation main] + 108
    38  Foundation                          0x028e8d84 -[__NSOperationInternal _start:] + 697
    39  Foundation                          0x028e8ac4 -[NSOperation start] + 83
    40  Foundation                          0x028e8902 __NSOQSchedule_f + 245
    41  libdispatch.dylib                   0x04a2f9cd _dispatch_client_callout + 14
    42  libdispatch.dylib                   0x04a13650 _dispatch_queue_drain + 2227
    43  libdispatch.dylib                   0x04a12b04 _dispatch_queue_invoke + 570
    44  libdispatch.dylib                   0x04a157bb _dispatch_root_queue_drain + 550
    45  libdispatch.dylib                   0x04a1558e _dispatch_worker_thread3 + 115
    46  libsystem_pthread.dylib             0x04d4f270 _pthread_wqthread + 1050
    47  libsystem_pthread.dylib             0x04d4cf82 start_wqthread + 34
)


This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes.  This will cause an exception in a future release.
 Stack:(
    0   CoreFoundation                      0x004eda84 __exceptionPreprocess + 180
    1   libobjc.A.dylib                     0x041d8e02 objc_exception_throw + 50
    2   CoreFoundation                      0x004ed9ad +[NSException raise:format:] + 141
    3   Foundation                          0x02b0974b _AssertAutolayoutOnMainThreadOnly + 96
    4   Foundation                          0x02931561 -[NSISEngine optimize] + 67
    5   Foundation                          0x02932024 -[NSISEngine withBehaviors:performModifications:] + 245
    6   Foundation                          0x029354a4 -[NSISEngine withAutomaticOptimizationDisabled:] + 48
    7   UIKit                               0x01256d98 -[UIView(UIConstraintBasedLayout) _calculatedSystemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:hasIntentionallyCollapsedHeight:] + 1194
    8   UIKit                               0x012587e9 -[UIView(AdditionalLayoutSupport) _systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:hasIntentionallyCollapsedHeight:] + 972
    9   UIKit                               0x01258343 -[UIView(UIConstraintBasedLayout) systemLayoutSizeFittingSize:withHorizontalFittingPriority:verticalFittingPriority:] + 127
    10  UIKit                               0x0125838f -[UIView(UIConstraintBasedLayout) systemLayoutSizeFittingSize:] + 71
    11  UIKit                               0x0137b017 -[_UIAlertControllerView _minimumSizeForAllActions] + 589
    12  UIKit                               0x0137789b -[_UIAlertControllerView _itemSizeForHorizontalLayout:] + 451
    13  UIKit                               0x01377acf -[_UIAlertControllerView _canLayOutActionsHorizontally] + 108
    14  UIKit                               0x01377ff7 -[_UIAlertControllerView _actionLayoutDirectionChanged] + 42
    15  UIKit                               0x0137d13a -[_UIAlertControllerView _updateBackdrop] + 577
    16  UIKit                               0x0137bf85 -[_UIAlertControllerView _updateStyleForIdiomChange:] + 156
    17  UIKit                               0x0137beb1 -[_UIAlertControllerView _setVisualStyle:] + 296
    18  UIKit                               0x00bfebdd -[UIAlertController _updateProvidedStyleWithTraitCollection:] + 525
    19  UIKit                               0x00bfecd1 -[UIAlertController _updateProvidedStyle] + 68
    20  UIKit                               0x00bfee39 -[UIAlertController _resolvedStyleChanged] + 35
    21  UIKit                               0x00bfe30a -[UIAlertController viewDidLoad] + 98
    22  UIKit                               0x00a42a86 -[UIViewController _sendViewDidLoadWithAppearanceProxyObjectTaggingEnabled] + 44
    23  UIKit                               0x00a475a6 -[UIViewController loadViewIfRequired] + 1384
    24  UIKit                               0x00a479c5 -[UIViewController view] + 35
    25  UIKit                               0x00a63ba2 -[UIViewController _setPresentationController:] + 117
    26  UIKit                               0x00a5a1c6 -[UIViewController _presentViewController:modalSourceViewController:presentationController:animationController:interactionController:completion:] + 1503
    27  UIKit                               0x00a5c143 -[UIViewController _presentViewController:withAnimationController:completion:] + 5297
    28  UIKit                               0x00a5f34b __62-[UIViewController presentViewController:animated:completion:]_block_invoke + 397
    29  UIKit                               0x00a5f690 -[UIViewController _performCoordinatedPresentOrDismiss:animated:] + 493
    30  UIKit                               0x00a5f177 -[UIViewController presentViewController:animated:completion:] + 182
    31  UIKit                               0x013667ff -[_UIAlertControllerShimPresenterWindow presentAlertController:animated:completionBlock:] + 580
    32  UIKit                               0x01364912 -[_UIAlertControllerShimPresenter _presentAlertControllerAnimated:completion:] + 235
    33  UIKit                               0x00c11990 -[UIAlertView _showAnimated:] + 276
    34  UIKit                               0x00c11b76 -[UIAlertView show] + 41
    35  心动爱                           0x0012997a __37-[MainViewController checkAppVersion]_block_invoke + 762
    36  CFNetwork                           0x03692b62 __67+[NSURLConnection sendAsynchronousRequest:queue:completionHandler:]_block_invoke_2 + 177
    37  Foundation                          0x029e4a6b __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 12
    38  Foundation                          0x029088ff -[NSBlockOperation main] + 108
    39  Foundation                          0x028e8d84 -[__NSOperationInternal _start:] + 697
    40  Foundation                          0x028e8ac4 -[NSOperation start] + 83
    41  Foundation                          0x028e8902 __NSOQSchedule_f + 245
    42  libdispatch.dylib                   0x04a2f9cd _dispatch_client_callout + 14
    43  libdispatch.dylib                   0x04a13650 _dispatch_queue_drain + 2227
    44  libdispatch.dylib                   0x04a12b04 _dispatch_queue_invoke + 570
    45  libdispatch.dylib                   0x04a157bb _dispatch_root_queue_drain + 550
    46  libdispatch.dylib                   0x04a1558e _dispatch_worker_thread3 + 115
    47  libsystem_pthread.dylib             0x04d4f270 _pthread_wqthread + 1050
    48  libsystem_pthread.dylib             0x04d4cf82 start_wqthread + 34
)

什么意思呢?翻译过来大概是指说在一个异步线程修改了应用程序的布局,将会引起崩溃异常。。。。

然后反省了一下,记起以前师傅说过的话:耗时操作放在异步线程上,更新UI要放在主线程上。

我这里出现这个原因应该是:我在异步访问了一个网络请求后,解析从服务器返回的信息,然后马上就new了一个UIAlertView对象,准备弹窗提示,

这相当于在一个异步线程里面对UI进行了更新,所以导致出现了异常警告。

正确的作法是,异步访问了网络请求后, 如果想new个UIAlertView进行弹窗提示,应该去主线程进行。。。这样就OK了

原文链接:http://www.cnblogs.com/tandaxia/p/5000957.html

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏岑志军的专栏

iOS单独对年月日加减

2096
来自专栏Android源码框架分析

Android面试官装逼失败之:Activity的启动模式总结

2394
来自专栏JarvanMo的IT专栏

Android无法打开相册查看视频

最近公司做了一个项目需要查看手机视频,在android 8的模拟器上正常。在android 5.1的模拟器下却报了一个错误:

2262
来自专栏向治洪

iOS 轻量级存储

NSUserDefaults简介 在Android和ios都提供了本地轻量级数据存储,底层实现都是基于key-value的方式。Android里面的叫Share...

2488
来自专栏mukekeheart的iOS之旅

iOS学习——获取当前最顶层的ViewController

  在iOS开发过程中,我们经常性会需要获取当前页面的ViewController,然后利用ViewController进行一些操作,例如在最顶层的ViewCo...

7145
来自专栏潇涧技术专栏

Android Development Code Snippets

771
来自专栏漫漫深度学习路

python绘图:matplotlib绘图(2)

matplotlib绘图(2) plt.bar colors=["#348ABD","#A60628"] plt.bar([0,.7], prior, alph...

1925
来自专栏陈满iOS

iOS开发·NSDate日期基本操作方法

641
来自专栏静晴轩

Android之Intent用法全面总结

[代码] 调用拨号程序 // 给移动客服10086拨打电话 Uri uri = Uri.parse("tel:10086"); Intent intent = ...

3407
来自专栏一个会写诗的程序员的博客

在非Activity中使用startActivity:Calling startActivity() from outside of an Activity context requires the

activity继承了context重载了startActivity方法,如果使用acitvity中的startActivity,不会有任何限制。

1074

扫码关注云+社区