我有方法可以清除设备中的通讯录。方法如下。
-(void) clearAdressBook
{
ABAddressBookRef addrBook=ABAddressBookCreate();
CFArrayRef groups = ABAddressBookCopyArrayOfAllGroups(addrBook);
if(groups)
{
CFIndex numGroups = CFArrayGetCount(groups);
for(CFIndex idx=0; idx<numGroups; ++idx)
{
ABRecordRef groupItem = CFArrayGetValueAtIndex(groups, idx);
CFArrayRef people=
ABGroupCopyArrayOfAllMembers(groupItem);
if(people)
{
CFIndex peopleCount=CFArrayGetCount(people);
for(CFIndex ind=0;ind<peopleCount;++ind)
{
ABRecordRef person=CFArrayGetValueAtIndex(people, ind);
ABAddressBookRemoveRecord(addrBook, person, nil);
ABAddressBookSave(addrBook, NULL);
CFRelease(person);
}
CFRelease(people);//CRASH
}
}
}
CFRelease(groups);
}
当我发布 CFArrayRef 应用程序崩溃时,这里有什么问题?据我所知,我必须释放从 CF 方法返回的所有反对,其名称包含复制或创建权?