iOS: dispatch_get_global_queue QOS_CLASS_BACKGROUND crashes on 7.1.2

余生长醉 提交于 2019-12-31 03:31:27

问题


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

It works fine on both 7.1.2 and 8.1.3 versions.

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

回答1:


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.



来源:https://stackoverflow.com/questions/28947509/ios-dispatch-get-global-queue-qos-class-background-crashes-on-7-1-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!