无法设置ABPeoplePickerNavigationController的addressBook属性,而不会崩溃 [英] Can't set the addressBook property of ABPeoplePickerNavigationController without crashing
问题描述
因此,我创建一个地址簿,并删除没有地址的用户:
p> addressBook = ABAddressBookCreate();
NSArray * peopleList =(NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
NSLog(@addressBook中有%d个人,ABAddressBookGetPersonCount(addressBook));
for(id peopleRecord in peopleList){
ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord,kABPersonAddressProperty);
CFIndex numberOfAddresses = ABMultiValueGetCount(mv);
if(numberOfAddresses == 0){
CFErrorRef err;
ABAddressBookRemoveRecord(addressBook,(ABRecordRef)peopleRecord,& err);
}
}
[peopleList release];
NSLog(@现在有%d个人在addressBook,ABAddressBookGetPersonCount(addressBook));
ABPeoplePickerNavigationController * peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
NSNumber * addressProp = [NSNumber numberWithInt:kABPersonAddressProperty];
[peoplePicker setAddressBook:addressBook];
peoplePicker.displayedProperties = [NSArray arrayWithObject:addressProp];
[peoplePicker setPeoplePickerDelegate:self];
[self presentModalViewController:peoplePicker animated:YES];
有关信息,在过滤前我有125条记录,过滤后我有93条记录。
当我显示peoplePicker并滚动通过它,它崩溃与:
***由于未捕获异常NSRangeException终止应用程序,原因:'*** - [NSCFArray objectAtIndex:]:index(49)超出边界(49)'
任何想法出了什么问题?
NSRangeException值是49(而不是一些数字在93和125之间),我最初怀疑它不直接与这个地址簿相关。为 objc_exception_throw
添加一个断点。这将导致你在异常的时候进入调试器,让你看看谁实际上抛出它。
I want to display an ABPeoplePicker with only people who have a geographic address defined.
So I create an addressBook and remove people that dont have an address:
addressBook = ABAddressBookCreate();
NSArray *peopleList = (NSArray *)ABAddressBookCopyArrayOfAllPeople( addressBook );
NSLog(@"There are %d people in addressBook", ABAddressBookGetPersonCount(addressBook));
for (id peopleRecord in peopleList) {
ABMultiValueRef mv = ABRecordCopyValue((ABRecordRef)peopleRecord, kABPersonAddressProperty);
CFIndex numberOfAddresses = ABMultiValueGetCount(mv);
if( numberOfAddresses == 0 ) {
CFErrorRef err;
ABAddressBookRemoveRecord( addressBook, (ABRecordRef)peopleRecord, &err);
}
}
[peopleList release];
NSLog(@"There are now %d people in addressBook", ABAddressBookGetPersonCount(addressBook));
ABPeoplePickerNavigationController *peoplePicker = [[ABPeoplePickerNavigationController alloc] init];
NSNumber* addressProp = [NSNumber numberWithInt:kABPersonAddressProperty];
[peoplePicker setAddressBook:addressBook];
peoplePicker.displayedProperties = [NSArray arrayWithObject:addressProp];
[peoplePicker setPeoplePickerDelegate:self];
[self presentModalViewController:peoplePicker animated:YES];
For info, before filtering I have 125 records, and after filtering I have 93 records.
When I display the peoplePicker and scroll through it, it crashes with:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFArray objectAtIndex:]: index (49) beyond bounds (49)'
Any idea what's wrong?
The fact that the NSRangeException's value is 49 (rather than some number between 93 and 125), I initially suspect that it's not directly related to this address book. Add a breakpoint for objc_exception_throw
. That will cause you to drop into the debugger at the point of the exception, letting you see who's actually throwing it.
这篇关于无法设置ABPeoplePickerNavigationController的addressBook属性,而不会崩溃的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!