我使用以下代码从地址簿中检索不同的地址字段。它适用于名称和一些属性,但崩溃与地址。我怀疑地址是一个int而不是字符串但是在文档中找不到任何东西来解释为什么它应该是不同的。非常感谢任何建议:
//This works:
CFStringRef jobtitleRef = nil;
jobtitleRef = ABRecordCopyValue(addressBookRecord, kABPersonJobTitleProperty);
NSString *jobtitle = @"";
if (jobtitleRef!=nil) {
jobtitle =[jobtitle stringByAppendingString:(__bridge NSString *)jobtitleRef];
}
//But this crashes
CFStringRef addr1Ref = nil;
addr1Ref = ABRecordCopyValue(addressBookRecord, kABPersonAddressProperty);
NSString *addr1 = @"";
if (addr1Ref!=nil) {
addr1 = [addr1 stringByAppendingString:(__bridge NSString *)addr1Ref]; //crashes on this line
}
修改
在另一个问题中找到答案:
ABMultiValueRef st = ABRecordCopyValue(person, kABPersonAddressProperty);
if (ABMultiValueGetCount(st) > 0) {
CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(st, 0);
self.street.text = CFDictionaryGetValue(dict, kABPersonAddressStreetKey);
}