This application is modifying the autolayout engine from a background thread, which can lead to engine corruption and weird crashes

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
)
View Code

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

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

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

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

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

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

posted @ 2015-11-27 16:04  谈晓鸣  阅读(1430)  评论(0编辑  收藏  举报