在ios 7上使用dispatch_get_global_queue时会发生EXC_BAD_INSTRUCTION(swift) [英] EXC_BAD_INSTRUCTION happens when using dispatch_get_global_queue on ios 7(swift)

查看:477
本文介绍了在ios 7上使用dispatch_get_global_queue时会发生EXC_BAD_INSTRUCTION(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)
    }

上面是我的代码

适用于ios8

但是在ios7上,它崩溃了。下面是崩溃日志

above is my code
works fine on ios8
but on ios7, it crashes. below is 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
...

请帮助,我真的google了很多,没有发现任何有用的东西。
不可能dispatch_get_global_queue无法在ios7上运行,所以一定是我犯了一些愚蠢的错误。只是不要做什么

please help, i really googled a lot and found nothing useful. it's impossible dispatch_get_global_queue can't work on ios7, so must be some stupid mistake i have made. just don't what

BTW
i使用
Mac OS X 10.10.2
xcode6.1.1

BTW i am using Mac OS X 10.10.2 xcode6.1.1

推荐答案

找到我发布后几秒钟的原因。
似乎不是我的傻瓜,但苹果的文件

found out the reason seconds after i posted. it seems not me being stupid, but apple's document

QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_USER_INITIATED, QOS_CLASS_UTILITY, or QOS_CLASS_BACKGROUND

不能在ios7上使用,尽管
https://developer.apple.com/library/ios/documentation/Performance/Reference / GCD_libdispatch_Ref /#// apple_ref / c / func / dispatch_get_global_queue

不打扰其中的任何一个
而是使用

can not be used on ios7, though https://developer.apple.com/library/ios/documentation/Performance/Reference/GCD_libdispatch_Ref/#//apple_ref/c/func/dispatch_get_global_queue
doesn't bother to metion any of it instead use

DISPATCH_QUEUE_PRIORITY_HIGH, DISPATCH_QUEUE_PRIORITY_DEFAULT, DISPATCH_QUEUE_PRIORITY_LOW, DISPATCH_QUEUE_PRIORITY_BACKGROUND

这篇关于在ios 7上使用dispatch_get_global_queue时会发生EXC_BAD_INSTRUCTION(swift)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆