Main Thread Checker: UI API called on a background thread

在开发的过程中遇到一个警告问题,如下:

Main Thread Checker: UI API called on a background thread: -[UIWebView loadRequest:] PID: 18274, TID: 1210667, Thread name: (none), Queue name: com.apple.root.default-qos, QoS: 21 Backtrace: 4  quickofficeOA                      0x0000000106486af4 __40-[approveLookViewController viewDidLoad]_block_invoke.99 + 356 5  libdispatch.dylib                  0x00000001123c07ab _dispatch_call_block_and_release + 12 6  libdispatch.dylib                  0x00000001123c17ec _dispatch_client_callout + 8 7  libdispatch.dylib                  0x00000001123c6619 _dispatch_queue_override_invoke + 1451 8  libdispatch.dylib                  0x00000001123cd36c _dispatch_root_queue_drain + 664 9  libdispatch.dylib                  0x00000001123cd076 _dispatch_worker_thread3 + 132 10  libsystem_pthread.dylib            0x00000001128ec169 _pthread_wqthread + 1387 11  libsystem_pthread.dylib            0x00000001128ebbe9 start_wqthread + 13


出现警告的代码:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSString*body = [selfexamineTheFilePathStr:_path];

        if(body) {

            body = [bodystringByReplacingOccurrencesOfString:@"\n" withString:@"

"];

            [_webViewloadHTMLString:bodybaseURL:nil];

        }else{

            NSURLRequest*request = [NSURLRequestrequestWithURL:[NSURLfileURLWithPath:_path]];

            [_webViewloadRequest:request];

        }

    });

修复后的代码:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

        NSString*body = [self examineTheFilePathStr:_path];

        if (body)  {

            body = [bodystringByReplacingOccurrencesOfString:@"\n" withString:@"
"];

            [_webViewloadHTMLString:bodybaseURL:nil];

        } else {

            NSURLRequest*request = [NSURLRequestrequestWithURL:[NSURLfileURLWithPath:_path]];

            dispatch_async(dispatch_get_main_queue(), ^{

                [_webViewloadRequest:request];

            });

        }

    });

你可能感兴趣的:(Main Thread Checker: UI API called on a background thread)