CFStringRef版本在nil时给出错误的访问权限

时间:2015-12-24 10:25:02

标签: ios objective-c xcode7 addressbook cfstring

ABMultiValueRef phonesRef = ABRecordCopyValue(person, kABPersonPhoneProperty);
    for (int i=0; i < ABMultiValueGetCount(phonesRef); i++)
    {
        CFStringRef currentPhoneLabel = ABMultiValueCopyLabelAtIndex(phonesRef, i);
        CFStringRef currentPhoneValue = ABMultiValueCopyValueAtIndex(phonesRef, i);

        if (currentPhoneLabel != nil && currentPhoneValue != nil)
        {
            if (CFStringCompare(currentPhoneLabel, kABPersonPhoneMobileLabel, 0) == kCFCompareEqualTo)
            {
                [contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"workNumber"];
            }

            if (CFStringCompare(currentPhoneLabel, kABHomeLabel, 0) == kCFCompareEqualTo)
            {
                [contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"homeNumber"];
            }
        }
        else if (currentPhoneValue != nil && currentPhoneLabel == nil)
        {
            [contactInfoDict setObject:(__bridge NSString *)currentPhoneValue forKey:@"workNumber"];
        }

        CFRelease(currentPhoneLabel);
        CFRelease(currentPhoneValue);
    }
    CFRelease(phonesRef);

这是我将联系电话导入我的ios应用程序的代码,但是当currentPhoneLabel为CFRelease(currentPhoneLabel)的nil xocde时。 我不知道为什么会这样。 任何帮助都会非常明显。

由于

1 个答案:

答案 0 :(得分:0)

您已经在代码中的其他位置设置了警卫,因此您只需要在每次调用String s = "https://www.thomas-bayer.com/axis2/services/BLZService?wsdl"; String regex = "(^http.?://)(.*?)([/\\?]{1,})(.*)"; System.out.println("1: " + s.replaceAll(regex, "$1")); System.out.println("2: " + s.replaceAll(regex, "$2")); System.out.println("3: " + s.replaceAll(regex, "$3")); System.out.println("4: " + s.replaceAll(regex, "$4")); 时添加警卫:

CFRelease()