gpt4 book ai didi

ios - 调用 CFRelease(ABAddressBookRef ref) 时崩溃

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:31:20 30 4
gpt4 key购买 nike

这是我的代码,运行最后一行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);

Xcode when crash

最佳答案

您不拥有 obj_pobj_g,因此当您释放它们的桥接引用然后从该枚举 block 中弹出时,它们会被过度释放。只有使用 CreateCopy 访问它们时,您才拥有核心基础对象。

关于ios - 调用 CFRelease(ABAddressBookRef ref) 时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14035489/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com