これは私のコードです、最後の行を実行しCFRelease(addressBook)
、プログラムがクラッシュします!助けて〜!
ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
NSMutableArray *groups = [NSMutableArray arrayWithCapacity:ABAddressBookGetGroupCount(addressBook)];
NSMutableArray *people = [NSMutableArray arrayWithCapacity:ABAddressBookGetGroupCount(addressBook)];
[(NSArray *)CFBridgingRelease(ABAddressBookCopyArrayOfAllGroups(addressBook)) enumerateObjectsUsingBlock:^(id obj_g, NSUInteger idx, BOOL *stop) {
ABRecordRef g = (__bridge ABRecordRef)obj_g;
NSString *gname = CFBridgingRelease(ABRecordCopyCompositeName(g));
NSMutableArray *gp = [[[NSArray alloc] init] mutableCopy];
[(NSArray *)CFBridgingRelease(ABGroupCopyArrayOfAllMembers(g)) enumerateObjectsUsingBlock:^(id obj_p, NSUInteger idx, BOOL *stop) {
ABRecordRef p = (__bridge ABRecordRef)obj_p;
ABMultiValueRef numbers = ABRecordCopyValue(p, kABPersonPhoneProperty);
NSString *pname = CFBridgingRelease(ABRecordCopyCompositeName(p));
[(NSArray *) CFBridgingRelease(ABMultiValueCopyArrayOfAllValues(numbers)) enumerateObjectsUsingBlock:^(id obj_n, NSUInteger idx, BOOL *stop) {
NSString *pnumber = CFBridgingRelease(CFBridgingRetain(obj_n));
MasMsContact *new_c = [[MasMsContact alloc] init];
new_c.name = pname;
new_c.number = pnumber;
new_c.group = gname;
[gp addObject:new_c];
}];
CFRelease(numbers);
CFRelease(p);
}];
CFRelease(g);
[people addObject:[gp copy]];
[groups addObject:gname];
}];
#warning crash when release addressBook, why ???
if (addressBook) CFRelease(addressBook);