地址簿中出现奇怪的ios 5错误

时间:2011-12-07 18:04:08

标签: ios5 abaddressbook

我已完成以下操作以从地址簿中获取用户信息的记录。

- (ABRecordRef)findRecordNSString *)phoneNumber
{
if (phoneNumber == nil)
return nil;
ABAddressBookRef addressBook = ABAddressBookCreate();

CFArrayRef all = ABAddressBookCopyArrayOfAllPeople(addressBook);

CFIndex n = ABAddressBookGetPersonCount(addressBook);

ABRecordRef record;

//NSLog(@"The Record : %d", record);

int count = 0;

for( int i = 0 ; i < n ; i++ )
{
ABRecordRef ref = CFArrayGetValueAtIndex(all, i);

ABMultiValueRef phones = ABRecordCopyValue(ref, kABPersonPhoneProperty);
for(CFIndex j = 0; j < ABMultiValueGetCount(phones); j++)
{

CFStringRef phoneNumberRef = ABMultiValueCopyValueAtIndex(phones, j);

NSString *newPhoneNumber = (NSString *)phoneNumberRef;



if([newPhoneNumber isEqualToStringhoneNumber])
{
//NSLog(@"Phone Ref: %@", phoneNumberRef);
NSLog(@"Record New: %d", ref);
record = ref;

i=(int)n;
count = 1;
}
CFRelease(phoneNumberRef);
[newPhoneNumber release];
}

}
[addressBook release];
return record;
}

但是当我尝试在ios5设备中打开viewController但我在模拟器和ios 4中工作时出现错误。 错误是

Program received signal: “EXC_BAD_ACCESS”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Can't find dlopen function, so it is not possible to load shared libraries.)

此错误之后如果我通过双击主页按钮强行关闭应用程序然后手动退出应用程序将只显示黑屏。对此有何想法?

1 个答案:

答案 0 :(得分:0)

刚评论了这一行

CFIndex n = ABAddressBookGetPersonCount(addressBook); 

并替换为此以获取记录总数

CFIndex n = CFArrayGetCount(all);

因为所有(数组)和变量n的计数不同。

希望这也有助于其他人。