0

访问用户通讯录时出现问题。我的代码是

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

        }

登录 home_email、work_email、basic_email 时收到 Exc_bad_access 信号。

4

1 回答 1

0

我自己找到了解决方案。我声明了 home_email、work_email、basic_email 但没有初始化它们,当我在日志中打印它们时,它们还没有初始化。这解决了我的问题。

于 2013-05-22T06:00:46.497 回答