Search code examples
iphoneaddressbook

Program receives Exc_bad_access signal and crashes


I am issue while accessing the address book of user. My code is

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];
            }

        }

There is Exc_bad_access signal received when I to log the home_email, work_email, basic_email.


Solution

  • I found the solution for this my self. I declared the home_email, work_email, basic_email but didn't initialized them and by the time i was printing them in log those were not initialized. This solved my issue.