0

I am using the following code to retrieve different address fields from the Addressbook. It works okay for name and some properties but crashes with address. I suspect that the address is an int rather than string but can't find anything in the docs to explain why it should be different. Would appreciate any suggestions:

//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
            }

Edit:

Found the answer in another question:

ABMultiValueRef st = ABRecordCopyValue(person, kABPersonAddressProperty);
if (ABMultiValueGetCount(st) > 0) {
    CFDictionaryRef dict = ABMultiValueCopyValueAtIndex(st, 0);
    self.street.text = CFDictionaryGetValue(dict, kABPersonAddressStreetKey);
}
user1904273
  • 4,562
  • 11
  • 45
  • 96
  • 1
    As a person can have multiple addresses `kABPersonAddressProperty` is a multivalue property (`ABMultiValueRef`) not `CFStringRef` – vadian Sep 06 '15 at 11:34
  • Which line produces a crash? Please be more specific (e.g. post a crash log) – Matteo Pacini Sep 06 '15 at 11:34
  • Vadian is correct. See http://stackoverflow.com/questions/8329006/how-to-get-street-address-from-abpeoplepickernavigationcontroller for answer (also in edit above) – user1904273 Sep 06 '15 at 12:05

0 Answers0