iOS:dispatch_get_global_queue QOS_CLASS_BACKGROUND在7.1.2上崩溃 [英] iOS: dispatch_get_global_queue QOS_CLASS_BACKGROUND crashes on 7.1.2

查看:117
本文介绍了iOS:dispatch_get_global_queue QOS_CLASS_BACKGROUND在7.1.2上崩溃的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have following snippets of code that fetches contacts by using block:

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.2 8.1.3 版本。

但是当我尝试更改 dispatch_get_main_queue dispatch_get_global_queue(QOS_CLASS_BACKGROUND,0)它适用于 8.1.3 崩溃 on 7.1.2

However when I try to change dispatch_get_main_queue to dispatch_get_global_queue(QOS_CLASS_BACKGROUND, 0) it works on 8.1.3 but crashes on 7.1.2

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
                              //...
                            }
                        });
                    });


推荐答案

QOS_CLASS _ 标识符。如果要支持iOS 7,则需要使用 DISPATCH_QUEUE_PRIORITY _ 标识符。

The QOS_CLASS_ identifiers were introduced in iOS 8. You need to use the DISPATCH_QUEUE_PRIORITY_ identifiers if you want to support iOS 7.

这篇关于iOS:dispatch_get_global_queue QOS_CLASS_BACKGROUND在7.1.2上崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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