0
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 时。我不知道为什么会这样。任何帮助将是非常可观的。

谢谢

4

1 回答 1

0

你已经在代码的其他地方有了守卫,所以你只需要在每次调用时添加一个守卫CFRelease()

if (currentPhoneLabel != NULL)
    CFRelease(currentPhoneLabel);
// etc.
于 2015-12-24T10:56:05.950 回答