请你看看我的代码:
(void)loadContactsFromAddressBook {
ABAddressBookRef addressBook = ABAddressBookCreate();
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(addressBook);
CFIndex count = ABAddressBookGetPersonCount(addressBook);
ABRecordRef person;
for (int i = 0; i < count; i++) {
person = CFArrayGetValueAtIndex(allPeople, i);
CFStringRef cfStr = ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString* firstName = (NSString*) cfStr;
[contacts addObject:firstName];
CFRelease(cfStr);
}
CFRelease(addressBook);
CFRelease(allPeople);
}
我在for block之后尝试了CFRelease(person),但是应用程序崩溃了“EXC_BAD_ACCESS”。如果我删除CFRelease(person),该应用程序将起作用。
答案 0 :(得分:9)
你没有创建这个人,你只引用了它。 在此处插入子支持笑话。