Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
346 views
in Technique[技术] by (71.8m points)

ios - iOS9 - This application is modifying the autolayout engine from a background thread -- where?

For searching, the error message is:

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.

I know this means some UIKit code is called from a background thread, and I know the solution is to wrap the code in

dispatch_async(dispatch_get_main_queue(), ^(void){ <code> });

My problem is locating where to do that, as none of the printed stack traces reference my app code. My evidence to prove this negative is searching (command-f) in the debug output window for the name of my app; I have 24 stack traces dumped out and my app name is not in any of them, except at the top with the error message. I can post one of them, but that doesn't seem very useful.

In the cases I am working on today, this is happening when transitioning view controllers, after viewWillDisappear() and before viewWillAppear(). I have found parts of my code to wrap dispatch_async() around, but those are all handled now. I have breakpoints and debug messages where objects relevant to the view controllers are allocated and deallocated, and they all trigger after the exception messages appear. This is happening both on the simulator and my iOS9 iPhone, both in debug and release modes.

How can I identify the background code which is apparently modifying the UI?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

This code PSPDFUIKitMainThreadGuard causes assertions on UIKit access outside the main thread

Steps to use:

  1. Add to project and compile this file without ARC
  2. Move PSPDFAssert definition to the first of the file
  3. Comment calling of PSPDFLogError as it is not defined
  4. import <UIKit/UIKit.h>

Your app will crash and stop with any attemption to modify any UI element from background thread

For swift use the following code: NBUIKitMainThreadGuard


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...