ios8abrecordref

Retrieve address from ABRecordRef


I need to get address information for calculating shipping and taxes rates for purchasing items on my app. I wanna use Apple Pay, thus I receive record as ABRecordRef instance. I've tried

NSString *zip = (__bridge NSString *)(ABRecordCopyValue(address, kABPersonAddressZIPKey));

but it causes EXC_BAD_ACCESS. I'm sure there should be a way to make it work, does anyone know it?


Solution

  • Figured it out finally:

    CFTypeRef addressProperty = ABRecordCopyValue((ABRecordRef)address, kABPersonAddressProperty);
    NSDictionary *addressDict = (__bridge NSDictionary *)CFArrayGetValueAtIndex((CFArrayRef)ABMultiValueCopyArrayOfAllValues(addressProperty), 0);
    

    Resulting dictionary looks like this:

    {
        City = Hillsborough;
        CountryCode = us;
        State = CA;
        ZIP = 94010;
    }