我遇到了一个问题NSMutableArray
。我用它来存储联系人详细信息表单地址簿。我在通讯录中有 300 个联系人。但是我的应用程序会崩溃。我用过这段代码
+(NSMutableArray *)getcontactdetails
{
ABAddressBookRef addressBook;
CFArrayRef allSources;
NSMutableArray *list = [[NSMutableArray alloc] init];
addressBook = ABAddressBookCreate();
ABRecordRef source = ABAddressBookCopyDefaultSource(addressBook);
allSources = ABAddressBookCopyArrayOfAllPeopleInSourceWithSortOrdering(addressBook, source, kABPersonFirstNameProperty);
CFIndex nPeople = ABAddressBookGetPersonCount(addressBook);
if(nPeople != 0){
for (CFIndex i = 0; i < nPeople; i++)
{
//common field
NSString *first_name =[[[NSString alloc] init] autorelease];
contact_details *phone_book_data=[[contact_details alloc] init];
ABRecordRef aSource = CFArrayGetValueAtIndex(allSources,i);
CFStringRef firstName = ABRecordCopyValue(aSource, kABPersonFirstNameProperty);
first_name=[NSString stringWithFormat:@"%@",firstName];
if ([first_name isEqualToString:@"(null)"] || first_name == nil || first_name.length == 0) {
}
else{
phone_book_data.FirstName=[NSString stringWithFormat:@"%@",first_name];
}
[list addObject:phone_book_data];
phone_book_data=nil;
[phone_book_data release];
}
CFRelease(allSources);
}
[self current_function_name:@"Finished getcontactdetails"];
return list;
}
我在控制台上有这些:
9 月 3 日 23:09:20 iPhone ReportCrash[1378]:为进程 intooch[1373] 制定崩溃报告 9 月 3 日 23:09:21 iPhone com.apple.launchd[1] (UIKitApplication:com.inTooch.inTooch[0x6b8a][ 1373]) : (UIKitApplication:com.inTooch.inTooch[0x6b8a]) 作业似乎已崩溃:分段错误:3 月 11 日 23:09:21 iPhone SpringBoard[52]:应用程序“inTooch”异常退出,信号 11:分段故障:9 月 3 日 11 日 23:09:21 iPhone ReportCrash [1378]:libMobileGestalt computeUniqueDeviceID:bb 返回 imei 的总时间:0
我是如何解决这个问题的?
提前致谢.....