iOS:dispatch_get_global_queue QOS_CLASS_BACKGROUND在7.1.2崩溃

时间:2015-03-09 16:50:25

标签: ios objective-c contacts

我有以下代码片段,通过使用块来获取联系人:

if (&ABAddressBookCreateWithOptions != NULL) {
            CFErrorRef error = nil;

            addressBook = ABAddressBookCreateWithOptions(NULL, &error);

            ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {

                dispatch_sync(dispatch_get_main_queue(), ^{
                        if (error) {
                            //...
                        } else if (!granted) {
                            //...
                        } else {
                            // access granted
                          //...
                        }
                    });
                });

它适用于7.1.28.1.3版本。

但是,当我尝试将dispatch_get_main_queue更改为dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0)时,8.1.3可以使用7.1.2崩溃 <{1}}

if (&ABAddressBookCreateWithOptions != NULL) {
                CFErrorRef error = nil;

                addressBook = ABAddressBookCreateWithOptions(NULL, &error);

                ABAddressBookRequestAccessWithCompletion(addressBook, ^(bool granted, CFErrorRef error) {
                        dispatch_sync(dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0), ^{ // BAD ACCESS
                    if (error) {
                                //...
                            } else if (!granted) {
                                //...
                            } else {
                                // access granted
                              //...
                            }
                        });
                    });

1 个答案:

答案 0 :(得分:5)

在iOS 8中引入了QOS_CLASS_标识符。如果要支持iOS 7,则需要使用DISPATCH_QUEUE_PRIORITY_标识符。