CFStringRef 版本为 nil 时提供错误访问
CFStringRef release gives bad access when it is nil
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 时。
我不知道为什么会这样。
任何帮助将不胜感激。
谢谢
你在代码的其他地方已经有了守卫,所以你只需要在每次调用 CFRelease()
时也添加一个守卫:
if (currentPhoneLabel != NULL)
CFRelease(currentPhoneLabel);
// etc.
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 时。 我不知道为什么会这样。 任何帮助将不胜感激。
谢谢
你在代码的其他地方已经有了守卫,所以你只需要在每次调用 CFRelease()
时也添加一个守卫:
if (currentPhoneLabel != NULL)
CFRelease(currentPhoneLabel);
// etc.