iOS运行时报错:This application is modifying the autolayout engine from a background thread after the

来源:互联网 发布:有没有鬼知乎 编辑:程序博客网 时间:2024/05/21 17:36

iOS 运行时报错:This application is modifying the autolayout engine from a
background thread after the engine was accessed from the main thread.
This can lead to engine corruption and weird crashes.

2017-12-04 09:34:48.814 xxthn_iOS_ch[1620:623172] 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                      0x0000000182c86dc8 <redacted> + 148,    1   libobjc.A.dylib                     0x00000001822ebf80 objc_exception_throw + 56,    2   CoreFoundation                      0x0000000182c86cf8 <redacted> + 0,    3   Foundation                          0x0000000183737b2c <redacted> + 88,    4   Foundation                          0x00000001837379f0 <redacted> + 56,    5   Foundation                          0x00000001835bd15c <redacted> + 56,    6   Foundation                          0x00000001835b8d1c <redacted> + 260,    7   UIKit                               0x0000000187ef0d98 <redacted> + 64,    8   UIKit                               0x0000000187ef18b0 <redacted> + 244,    9   UIKit                               0x0000000187f0f110 <redacted> + 108,    10  UIKit                               0x000000018867f7f0 <redacted> + 268,    11  UIKit                               0x00000001880fcaa0 <redacted> + 176,    12  UIKit                               0x00000001880eaa14 <redacted> + 52,    13  UIKit                               0x0000000187de41e4 <redacted> + 656,    14  QuartzCore                          0x000000018577298c <redacted> + 148,    15  QuartzCore                          0x000000018576d5c8 <redacted> + 292,    16  QuartzCore                          0x000000018576d488 <redacted> + 32,    17  QuartzCore                          0x000000018576cab8 <redacted> + 252,    18  QuartzCore                          0x000000018576c818 <redacted> + 500,    19  QuartzCore                          0x0000000185765ddc <redacted> + 80,    20  CoreFoundation                      0x0000000182c3c728 <redacted> + 32,    21  CoreFoundation                      0x0000000182c3a4cc <redacted> + 372,    22  CoreFoundation                      0x0000000182b64c70 CFRunLoopRunSpecific + 416,    23  WebCore                             0x0000000186b56108 <redacted> + 456,    24  libsystem_pthread.dylib             0x00000001828ebb28 <redacted> + 156,    25  libsystem_pthread.dylib             0x00000001828eba8c <redacted> + 0,    26  libsystem_pthread.dylib             0x00000001828e9028 thread_start + 4,)

直接翻译:这个程序通过后台线程修改了自动布局,它可能导致损坏和奇怪的崩溃。这将在以后的版本中引起异常。

其实就是主线程在运行的时候子线程修改了主线程UI的布局约束,在iOS开发中,所有的有关界面UI的更新操作必须奥在主线程中完成。这样的错误很容易出现在使用block的时候,解决的办法就是在刚才写的代码中有关针对UI更新的操作放到主线程中。

修改前的代码:

-(void)shareMyMsg:(NSString *)shareMag{    NSDictionary *dict = [shareMag andJSONStringToDictionary];    NSString *url = [dict valueForKey:@"url"];    if (NULLString(url)) {        return;    }         [self shareContent:content withUrl:url];}

修改后的代码:

-(void)shareMyMsg:(NSString *)shareMag{    NSDictionary *dict = [shareMag andJSONStringToDictionary];    NSString *url = [dict valueForKey:@"url"];    if (NULLString(url)) {        return;    }    //加入到主线程当中     dispatch_async(dispatch_get_main_queue(), ^{         [self shareContent:content withUrl:url];     }); }
阅读全文
1 0
原创粉丝点击