EXC_BAD_INSTRUCTION happens when using dispatch_get_global_queue on ios 7 (swift)

let downloadGroup = dispatch_group_create() var images = [UIImage]() var errors = [NSError]() dispatch_apply(UInt(urls.count), dispatch_get_global_queue(QOS_CLASS_USER_INITIATED, 0)) { (i) in dispatch_group_enter(downloadGroup) SimpleCache.sharedInstance.getImage(urls[Int(i)], completion: { (image, error) -> () in if let fullImage = image { images.append(fullImage) } else { if let err = error { DLog(err.description) errors.append(err) } } dispatch_group_leave(downloadGroup); }) } dispatch_group_notify(downloadGroup, dispatch_get_main_queue()) { completion(images, errors) } 

above my code
works great on ios8
but on ios7 it crashes. below - crash log

 ... Code Type: X86-64 (Native) Parent Process: launchd_sim [16908] Responsible: launchd_sim [16908] User ID: 501 Date/Time: 2015-02-19 11:31:34.346 +0900 OS Version: Mac OS X 10.10.2 (14C109) Report Version: 11 Anonymous UUID: C7FFC618-06B4-6AF8-3BCA-52E19DB5FF20 Sleep/Wake UUID: 5D2D4733-5669-4BBF-BE45-076C93211522 Time Awake Since Boot: 21000 seconds Time Since Wake: 5400 seconds Crashed Thread: 0 Dispatch queue: com.apple.main-thread Exception Type: EXC_BAD_INSTRUCTION (SIGILL) Exception Codes: 0x0000000000000001, 0x0000000000000000 Application Specific Information: CoreSimulator 110.4 - Device: iPhone 5s - Runtime: iOS 7.1 (11D167) - DeviceType: iPhone 5s Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 libswiftDispatch.dylib 0x0000000112cceaea _TF8Dispatch25dispatch_get_global_queueFTVSC11qos_class_tSu_CSo8NSObject + 26 ... 

please help, I really searched a lot and found nothing. this is impossible dispatch_get_global_queue cannot work on ios7, so there must be some kind of stupid mistake I made. just don't do that

BTW I am using Mac OS X 10.10.2 xcode6.1.1

+6
source share
2 answers

found out the reason for the seconds after i posted. It seems to me that I'm not a stupid, but apple document

 QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_USER_INITIATED, QOS_CLASS_UTILITY, or QOS_CLASS_BACKGROUND 

cannot be used on ios7, although https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/#//apple_ref/c/func/dispatch_get_global_queue
don't mind yourself use instead

 DISPATCH_QUEUE_PRIORITY_HIGH, DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_LOW, DISPATCH_QUEUE_PRIORITY_BACKGROUND 
+12
source

In my opinion, your main question is not the global queue, this is the dispatch_get_main_queue method. Please check it in the API documentation. It is used only in iOS 8.0+ , instead I use - (void)performSelectorOnMainThread:(SEL)aSelector withObject:(id)arg waitUntilDone:(BOOL)wait .

+1
source

Source: https://habr.com/ru/post/982720/


All Articles