FXImageView
FXImageView copied to clipboard
UI related task processing on Background thread
I am receiving this in error log when using asynchronous = YES
Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 7206, TID: 258580, Thread name: (none), Queue name: NSOperationQueue 0x60000022e280 (QOS: UNSPECIFIED), QoS: 0
Backtrace:
4 FXImageView 0x00000001074dab67 -[FXImageView cacheKey] + 215
5 FXImageView 0x00000001074db1f4 -[FXImageView processImage] + 52
6 FXImageView 0x00000001074d9e7f -[FXImageOperation main] + 63
7 Foundation 0x0000000109b51cd6 -[__NSOperationInternal _start:] + 778
8 libdispatch.dylib 0x000000010d37043c _dispatch_client_callout + 8
9 libdispatch.dylib 0x000000010d375af4 _dispatch_block_invoke_direct + 592
10 libdispatch.dylib 0x000000010d37043c _dispatch_client_callout + 8
11 libdispatch.dylib 0x000000010d375af4 _dispatch_block_invoke_direct + 592
12 libdispatch.dylib 0x000000010d375884 dispatch_block_perform + 109
13 Foundation 0x0000000109b4dce4 __NSOQSchedule_f + 342
14 libdispatch.dylib 0x000000010d37043c _dispatch_client_callout + 8
15 libdispatch.dylib 0x000000010d376856 _dispatch_continuation_pop + 967
16 libdispatch.dylib 0x000000010d374c86 _dispatch_async_redirect_invoke + 780
17 libdispatch.dylib 0x000000010d37c1f9 _dispatch_root_queue_drain + 772
18 libdispatch.dylib 0x000000010d37be97 _dispatch_worker_thread3 + 132
19 libsystem_pthread.dylib 0x000000010d82c5a2 _pthread_wqthread + 1299
20 libsystem_pthread.dylib 0x000000010d82c07d start_wqthread + 13
2017-10-11 14:50:12.061475+0500 Asma-ul-Husna[7206:258580] [reports] Main Thread Checker: UI API called on a background thread: -[UIView bounds]
PID: 7206, TID: 258580, Thread name: (none), Queue name: NSOperationQueue 0x60000022e280 (QOS: UNSPECIFIED), QoS: 0
Backtrace:
4 FXImageView 0x00000001074dab67 -[FXImageView cacheKey] + 215
5 FXImageView 0x00000001074db1f4 -[FXImageView processImage] + 52
6 FXImageView 0x00000001074d9e7f -[FXImageOperation main] + 63
7 Foundation 0x0000000109b51cd6 -[__NSOperationInternal _start:] + 778
8 libdispatch.dylib 0x000000010d37043c _dispatch_client_callout + 8
9 libdispatch.dylib 0x000000010d375af4 _dispatch_block_invoke_direct + 592
10 libdispatch.dylib 0x000000010d37043c _dispatch_client_callout + 8
11 libdispatch.dylib 0x000000010d375af4 _dispatch_block_invoke_direct + 592
12 libdispatch.dylib 0x000000010d375884 dispatch_block_perform + 109
13 Foundation 0x0000000109b4dce4 __NSOQSchedule_f + 342
14 libdispatch.dylib 0x000000010d37043c _dispatch_client_callout + 8
15 libdispatch.dylib 0x000000010d376856 _dispatch_continuation_pop + 967
16 libdispatch.dylib 0x000000010d374c86 _dispatch_async_redirect_invoke + 780
17 libdispatch.dylib 0x000000010d37c1f9 _dispatch_root_queue_drain + 772
18 libdispatch.dylib 0x000000010d37be97 _dispatch_worker_thread3 + 132
19 libsystem_pthread.dylib 0x000000010d82c5a2 _pthread_wqthread + 1299
20 libsystem_pthread.dylib 0x000000010d82c07d start_wqthread + 13
Although the images renders well but need to get rid from these thread related errors.
You should try:
- (NSString *)cacheKey { if (_cacheKey) return _cacheKey; __block NSString* s; dispatch_block_t block = ^{ s = [NSString stringWithFormat:@"%@_%@_%.2f_%.2f_%.2f_%@_%@_%.2f_%.2f_%@", _imageContentURL ?: [self imageHash:_originalImage], NSStringFromCGSize(self.bounds.size), _reflectionGap, _reflectionScale, _reflectionAlpha, [self colorHash:_shadowColor], NSStringFromCGSize(_shadowOffset), _shadowBlur, _cornerRadius, @(self.contentMode)]; }; if ([NSThread currentThread].isMainThread) { block(); } else { dispatch_sync(dispatch_get_main_queue(), block); } return s; }
For more info: https://developer.apple.com/documentation/code_diagnostics/main_thread_checker