我正在为我的应用程序使用地址簿框架,我的代码崩溃了 . 该代码如下所示
+(NSMutableArray *)getcontactdetails
{
[self current_function_name:@"Inside getcontactdetails"];
NSMutableArray *list = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook;
CFArrayRef allSources;
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 *basic_email =[[NSString alloc] init] ;
NSString *basic_mobile =[[NSString alloc] init] ;
//personal filed
NSString *Home_email =[[NSString alloc] init] ;
NSString*home_mobile =[[NSString alloc] init] ;
NSString*home_address =[[NSString alloc] init];
//business filed
NSString *work_email =[[NSString alloc] init] ;
NSString*work_mobile =[[NSString alloc] init] ;
NSString *work_address =[[NSString alloc] init] ;
contact_details *phone_book_data=[[contact_details alloc] init];
ABRecordRef aSource = CFArrayGetValueAtIndex(allSources,i);
// Fetch all groups included in the current source
NSString *first_name = (NSString*)ABRecordCopyValue(aSource, kABPersonFirstNameProperty);
if (![first_name isEqualToString:@"(null)"]){
phone_book_data.FirstName=[NSString stringWithFormat:@"%@",first_name];
}
NSLog(@"last_name:-%@",first_name);
NSString *last_name=(NSString*)ABRecordCopyValue(aSource, kABPersonLastNameProperty);
if ([last_name isEqualToString:@"(null)"] || last_name == nil || last_name.length == 0) {
phone_book_data.LastName=[NSString stringWithFormat:@""];
}
else{
phone_book_data.LastName=[NSString stringWithFormat:@"%@",last_name];
}
NSLog(@"last_name:-%@",last_name);
NSString *company_name=(NSString*)ABRecordCopyValue(aSource, kABPersonOrganizationProperty);
NSLog(@"companyname:-%@",company_name);
NSString *job_title=(NSString*)ABRecordCopyValue(aSource, kABPersonJobTitleProperty);
NSLog(@"jobtitle:-%@",job_title);
ABMultiValueRef address =(NSString*)ABRecordCopyValue(aSource, kABPersonAddressProperty);
NSString* addLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(address); i++) {
addLabel=(NSString*)ABMultiValueCopyLabelAtIndex(address, i);
if ([addLabel isEqualToString:(NSString*)kABWorkLabel])
{
work_address=@"exist";
}
if ([addLabel isEqualToString:(NSString*)kABHomeLabel])
{
home_address=@"exist";
}
}
NSLog(@"work_address:-%@",work_address);
NSLog(@"home_address:-%@",home_address);
ABMultiValueRef phones =(NSString*)ABRecordCopyValue(aSource, kABPersonPhoneProperty);
NSString* mobileLabel;
for(CFIndex i = 0; i < ABMultiValueGetCount(phones); i++) {
mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
{
home_mobile = [(NSString*)ABMultiValueCopyValueAtIndex(phones, i) retain];
}
if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
{
basic_mobile = [(NSString*)ABMultiValueCopyValueAtIndex(phones, i)retain];
}
if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMainLabel])
{
work_mobile = [(NSString*)ABMultiValueCopyValueAtIndex(phones, i)retain];
}
}
NSLog(@"home_mobile:-%@",home_mobile);
NSLog(@"basic_mobile:-%@",basic_mobile);
NSLog(@"work_mobile:-%@",work_mobile);
ABMultiValueRef email = ABRecordCopyValue(aSource, kABPersonEmailProperty);
NSString* email_lbl;
for(CFIndex i = 0; i < ABMultiValueGetCount(email); i++) {
email_lbl = (NSString*)ABMultiValueCopyLabelAtIndex(email, i);
if([email_lbl isEqualToString:(NSString *)kABHomeLabel])
{
Home_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
}
if([email_lbl isEqualToString:(NSString *)kABWorkLabel])
{
work_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
}
if([email_lbl isEqualToString:(NSString *)kABOtherLabel]){
basic_email = [(NSString*)ABMultiValueCopyValueAtIndex(email, i)retain];
}
}
NSLog(@"Home_email:-%@",Home_email);
NSLog(@"work_email:-%@",work_email);
NSLog(@"basic_email:-%@",basic_email);
if ([company_name isEqualToString:@""] || [company_name isEqualToString:@"(null)"] || company_name.length == 0) {
if ([job_title isEqualToString:@""] || [job_title isEqualToString:@"(null)"] || job_title.length == 0) {
if ([work_address isEqualToString:@""] || [work_address isEqualToString:@"(null)"] || work_address.length == 0) {
if ([work_mobile isEqualToString:@""] || [work_mobile isEqualToString:@"(null)"] || work_mobile.length == 0) {
if ([work_email isEqualToString:@""] || [work_email isEqualToString:@"(null)"] || work_email.length == 0) {
phone_book_data.Type=[NSString stringWithFormat:@"personal"];
}
else{
phone_book_data.Type=[NSString stringWithFormat:@"business"];
}
}
else{
phone_book_data.Type=[NSString stringWithFormat:@"business"];
}
}
else
{
phone_book_data.Type=[NSString stringWithFormat:@"business"];
}
}
else{
phone_book_data.Type=[NSString stringWithFormat:@"business"];
}
}
else{
phone_book_data.Type=[NSString stringWithFormat:@"business"];
}
if ([phone_book_data.Type isEqualToString:@"business"])
{
if ([work_mobile isEqualToString:@"(null)"] ||[work_mobile isEqualToString:@""] || work_mobile == nil || work_mobile.length == 0) {
if ([basic_mobile isEqualToString:@"(null)"] || basic_mobile == nil || basic_mobile.length == 0) {
phone_book_data.MobileNumber = @"";
}
else{
phone_book_data.MobileNumber=[NSString stringWithFormat:@"%@",basic_mobile];
}
}
else{
phone_book_data.MobileNumber=[NSString stringWithFormat:@"%@",work_mobile];
}
if ([work_email isEqualToString:@"(null)"] || work_email == nil || work_email.length == 0)
{
if ([basic_email isEqualToString:@"(null)"] || basic_email == nil || basic_email.length == 0) {
phone_book_data.emailaddress=@"";
}
else{
if ([basic_email rangeOfString:@"gmail"].location != NSNotFound || [basic_email rangeOfString:@"yahoo"].location != NSNotFound || [basic_email rangeOfString:@"hotmail"].location != NSNotFound ||[basic_email rangeOfString:@"aol"].location != NSNotFound) {
phone_book_data.emailaddress=basic_email;
}
else{
phone_book_data.emailaddress=@"";
}
}
}
else{
if ([work_email rangeOfString:@"gmail"].location == NSNotFound || [work_email rangeOfString:@"yahoo"].location == NSNotFound || [work_email rangeOfString:@"hotmail"].location == NSNotFound ||[work_email rangeOfString:@"aol"].location == NSNotFound) {
phone_book_data.emailaddress=@"";
}
else{
phone_book_data.emailaddress=work_email;
}
}
}
else{
if ([home_mobile isEqualToString:@"(null)"] || home_mobile == nil || home_mobile.length == 0) {
if (![basic_mobile isEqualToString:@"(null)"] || basic_mobile != nil || basic_mobile.length != 0) {
phone_book_data.MobileNumber=[NSString stringWithFormat:@"%@",basic_mobile];
}
else{
phone_book_data.MobileNumber = @"";
}
}
else{
phone_book_data.MobileNumber=[NSString stringWithFormat:@"%@",home_mobile];
}
if ([Home_email isEqualToString:@"(null)"] || Home_email == nil || Home_email.length == 0)
{
if ([basic_email isEqualToString:@"(null)"] || basic_email == nil || basic_email.length == 0) {
phone_book_data.emailaddress=@"";
}
else{
phone_book_data.emailaddress=basic_email;
}
}
else{
phone_book_data.emailaddress=Home_email;
}
}
if(ABPersonHasImageData(aSource)){
phone_book_data.contact_image = [UIImage imageWithData:(NSData *)ABPersonCopyImageData(aSource)];
}else{
phone_book_data.contact_image = [UIImage imageNamed:@"blank_image.png"];
}
phone_book_data.isselected=TRUE;
[list addObject:phone_book_data];
[phone_book_data release];
phone_book_data=nil;
}
}
CFRelease(allSources);
[self current_function_name:@"Finished getcontactdetails"];
return list;
}
现在我在崩溃报告中遇到了这个错误 .
ncident标识符:C28DCEAD-5DCD-469B-9349-46F59A92B25E
CrashReporter密钥:e1b5c8f591e28608a399ebe58d339df84ab3ae52
硬件型号:iPhone3,1
过程:tooch [163]
路径:/var/mobile/Applications/CB8405B7-8B2A-4226-9134-D99AC5474776/intooch.app/intooch
标识符:tooch
版本:??? (???)
代码类型:ARM(Native)
父流程:launchd [1]
日期/时间:2012-09-09 22:45:57.023 -0700
操作系统版本:iPhone OS 5.1.1(9B208)
报告版本:104
例外类型:EXC_BAD_ACCESS(SIGSEGV)
异常代码:KERN_INVALID_ADDRESS位于0x0000003d
坠毁线程:4
线程0名称:Dispatch queue:com.apple.main-thread
线程0:
0 libsystem_kernel.dylib 0x365ef004 0x365ee000 4100
1 libsystem_kernel.dylib 0x365ef1fa 0x365ee000 4602
2 CoreFoundation 0x369bd3ec 0x36930000 578540
3 CoreFoundation 0x369bc0ea 0x36930000 573674
4 CoreFoundation 0x3693f49e 0x36930000 62622
5 CoreFoundation 0x3693f366 0x36930000 62310
6 GraphicsServices 0x34b06432 0x34b02000 17458
7 UIKit 0x34be8cce 0x34bb7000 203982
8 intooch 0x00049648 0x45000 17992
9 tooch 0x00047138 0x45000 8504
线程1名称:Dispatch queue:com.apple.libdispatch-manager
线程1:
0 libsystem_kernel.dylib 0x365ef3a8 0x365ee000 5032
1 libdispatch.dylib 0x3741cea4 0x37410000 52900
2 libdispatch.dylib 0x3741cbc2 0x37410000 52162
线程2名称:WebThread
线程2:
0 libsystem_kernel.dylib 0x365ef004 0x365ee000 4100
1 libsystem_kernel.dylib 0x365ef1fa 0x365ee000 4602
2 CoreFoundation 0x369bd3ec 0x36930000 578540
3 CoreFoundation 0x369bc124 0x36930000 573732
4 CoreFoundation 0x3693f49e 0x36930000 62622
5 CoreFoundation 0x3693f366 0x36930000 62310
6 WebCore 0x31932c9c 0x31889000 695452
7 libsystem_c.dylib 0x32f3772e 0x32f29000 59182
8 libsystem_c.dylib 0x32f375e8 0x32f29000 58856
线程3:
0 libsystem_kernel.dylib 0x365ffcd4 0x365ee000 72916
1 libsystem_c.dylib 0x32f31f36 0x32f29000 36662
2 libsystem_c.dylib 0x32f31cc8 0x32f29000 36040
线程4崩溃:
0 AppSupport 0x34937e8a 0x3492e000 40586
1 AppSupport 0x3493806e 0x3492e000 41070
2 AddressBook 0x315b8edc 0x315a7000 73436
3 tooch 0x00058618 0x45000 79384
4 intooch 0x0004a0b6 0x45000 20662
5基金会0x32591a7a 0x32581000 68218
6基金会0x3262558a 0x32581000 673162
7 libsystem_c.dylib 0x32f3772e 0x32f29000 59182
8 libsystem_c.dylib 0x32f375e8 0x32f29000 58856
线程5:
0 libsystem_kernel.dylib 0x365ffcd4 0x365ee000 72916
1 libsystem_c.dylib 0x32f31f36 0x32f29000 36662
2 libsystem_c.dylib 0x32f31cc8 0x32f29000 36040
线程6名称:com.apple.NSURLConnectionLoader
主题6:
0 libsystem_kernel.dylib 0x365ef004 0x365ee000 4100
1 libsystem_kernel.dylib 0x365ef1fa 0x365ee000 4602
2 CoreFoundation 0x369bd3ec 0x36930000 578540
3 CoreFoundation 0x369bc124 0x36930000 573732
4 CoreFoundation 0x3693f49e 0x36930000 62622
5 CoreFoundation 0x3693f366 0x36930000 62310
6基金会0x32591bb2 0x32581000 68530
7基金会0x32591a7a 0x32581000 68218
8基金会0x3262558a 0x32581000 673162
9 libsystem_c.dylib 0x32f3772e 0x32f29000 59182
10 libsystem_c.dylib 0x32f375e8 0x32f29000 58856
线程7名称:com.apple.CFSocket.private
线程7:
0 libsystem_kernel.dylib 0x365ff570 0x365ee000 71024
1 CoreFoundation 0x369c163a 0x36930000 595514
2 libsystem_c.dylib 0x32f3772e 0x32f29000 59182
3 libsystem_c.dylib 0x32f375e8 0x32f29000 58856
线程4与ARM线程状态崩溃:
r0: 0x00000015 r1: 0x00000000 r2: 0x00000002 r3: 0x002ec510
r4: 0x00000000 r5: 0x0000000a r6: 0x0010a8e8 r7: 0x03f4ac9c
r8: 0x37cfef2f r9: 0x00000009 r10: 0x002ec510 r11: 0x00000122
ip: 0x3e61d63c sp: 0x03f4ac88 lr: 0x34938075 pc: 0x34937e8a
cpsr:0x00000030
我是如何修复此错误的?
谢谢你的进步......
1 回答
找到问题原因的最佳方法取决于您是否仍在开发并拥有代码,或者这是否是iTunes的崩溃报告 .
虽然ARM寄存器上有一个详细的Apple文档http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html但它并没有真正帮助找到问题 .
如果您有代码并且仍在开发中,我建议您需要在代码中放置NSLog和/或进行一些调试 .
如果它's a crash report from iTunes the best is to follow Apple'指南崩溃报告在这里http://developer.apple.com/library/ios/#technotes/tn2151/_index.html .
这是Apple描述的主要想法:
基本上,在这种情况下您需要做的就是将崩溃报告拖放到xCode中,但请确保您拥有dSym文件,以便xCode可以使用正确版本的应用程序版本对崩溃报告进行xymbolicate . 要做到这一点,您需要“构建和存档”每个分布式应用程序版本! ps描述所有细节的视频在会话317中...