如何获取iphone地址簿中所有联系人的家庭地址

Fah*_*mal 2 iphone objective-c

我正在开发一个应用程序,但现在我卡在了iphone地址簿中所有联系人的这一点(如何获得街道,邮编,州,国家).任何示例代码都非常有用.

saa*_*nib 7

您可以获取所有联系人的地址 -

ABAddressBookRef addressBook = ABAddressBookCreate();

NSArray *contactArr = (NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);

for (int i = 0; i < [contactArr count]; i++) 
{
    ABRecordRef person = (ABRecordRef)[contactArr objectAtIndex:i];

    ABMultiValueRef address = ABRecordCopyValue(person, kABPersonAddressProperty);

    for(CFIndex j = 0; j < ABMultiValueGetCount(address); j++)
    {
        CFDictionaryRef addressDict = ABMultiValueCopyValueAtIndex(address, j);

        CFStringRef streetValue = CFDictionaryGetValue(addressDict, kABPersonAddressStreetKey);

        CFStringRef cityValue = CFDictionaryGetValue(addressDict, kABPersonAddressCityKey);

        CFStringRef stateValue = CFDictionaryGetValue(addressDict, kABPersonAddressStateKey);

        CFStringRef zipValue = CFDictionaryGetValue(addressDict, kABPersonAddressZIPKey);

        CFStringRef countryValue = CFDictionaryGetValue(addressDict, kABPersonAddressCountryKey);

    }

}
Run Code Online (Sandbox Code Playgroud)