0

我正在为我的应用程序使用地址簿框架,并且我在该代码上遇到了崩溃。该代码如下所示

+(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;
}

现在我在崩溃报告中得到了这个错误。

事故标识符:C28DCEAD-5DCD-469B-9349-46F59A92B25E

CrashReporter 密钥:e1b5c8f591e28608a399ebe58d339df84ab3ae52

硬件型号:iPhone3,1

工艺:inoch [163]

路径:/var/mobile/Applications/CB8405B7-8B2A-4226-9134-D99AC5474776/intooch.app/intooch

标识符: inoch

版本: ???(???)

代码类型:ARM(本机)

父进程:launchd [1]

日期/时间:2012-09-09 22:45:57.023 -0700

操作系统版本:iPhone OS 5.1.1 (9B208)

报告版本:104

异常类型:EXC_BAD_ACCESS (SIGSEGV)

异常代码:0x0000003d 处的 KERN_INVALID_ADDRESS

崩溃的线程:4

线程 0 名称:调度队列:com.apple.main-thread

线程 0:

0 libsystem_kernel.dylib 0x365ef004 0x365ee000 + 4100

1 libsystem_kernel.dylib 0x365ef1fa 0x365ee000 + 4602

2 核心基础 0x369bd3ec 0x36930000 + 578540

3 核心基础 0x369bc0ea 0x36930000 + 573674

4 核心基础 0x3693f49e 0x36930000 + 62622

5 核心基础 0x3693f366 0x36930000 + 62310

6 图形服务 0x34b06432 0x34b02000 + 17458

7 UIKit 0x34be8cce 0x34bb7000 + 203982

8 进入 0x00049648 0x45000 + 17992

9 进入 0x00047138 0x45000 + 8504

线程 1 名称:调度队列: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 核心基础 0x369bd3ec 0x36930000 + 578540

3 核心基础 0x369bc124 0x36930000 + 573732

4 核心基础 0x3693f49e 0x36930000 + 62622

5 核心基础 0x3693f366 0x36930000 + 62310

6 网络核心 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 应用支持 0x34937e8a 0x3492e000 + 40586

1 应用支持 0x3493806e 0x3492e000 + 41070

2 地址簿 0x315b8edc 0x315a7000 + 73436

3 个 0x00058618 0x45000 + 79384

4 inoch 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 核心基础 0x369bd3ec 0x36930000 + 578540

3 核心基础 0x369bc124 0x36930000 + 573732

4 核心基础 0x3693f49e 0x36930000 + 62622

5 核心基础 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 核心基础 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

我如何修复这个错误?

提前感谢...

4

1 回答 1

0

找出问题原因的最佳方法取决于您是否仍在开发并拥有代码,或者这是否是来自 iTunes 的崩溃报告。

虽然这里有关于 ARM 寄存器的详细 Apple 文档http://developer.apple.com/library/ios/#documentation/Xcode/Conceptual/iPhoneOSABIReference/Articles/ARMv6FunctionCallingConventions.html它并没有真正帮助定位问题。

如果您有代码并且仍在开发中,我建议您需要将 NSLogs 放入代码中和/或进行一些调试。

如果它是来自 iTunes 的崩溃报告,最好在http://developer.apple.com/library/ios/#technotes/tn2151/_index.html遵循 Apple 关于崩溃报告的指南。

这是Apple描述的主要思想:

如果您通过 Xcode 的 Organizer 窗口从设备上获取崩溃日志,那么它们将在几秒钟后自动为您符号化。否则,您将需要通过将 .crash 文件导入到 Xcode Organizer 来自己符号化该文件。打开 Xcode Organizer,选择“Devices”选项卡,选择侧边栏顶部“LIBRARY”下的“Device Logs”,单击“Import”按钮并选择 .crash 文件。

基本上,在这种情况下,您需要做的就是将崩溃报告拖放到 xCode 中,但请确保您拥有 dSym 文件,以便 xCode 可以使用正确版本的应用程序构建来象征化崩溃报告。为此,您需要“构建和归档”每个分布式应用程序版本!ps描述所有细节的视频在会话317中......

于 2012-09-10T09:36:12.713 回答