Я пытаюсь добавить адрес «Дом» и «Работа» в мою запись Персона. Кажется, появляется только 1 (тот, который добавлен позже. Можно ли добавить несколько адресов для персоны и увидеть их в UnknownPersonViewController? Если да, то как мне это сделать?
Вот мой код:
void multiValueAddDictionaryValueAndLabel(ABMultiValueRef multi, CFDictionaryRef values, CFStringRef label) {
if (multi && values != NULL) {
ABMultiValueAddValueAndLabel(multi, values, label, NULL);
}
}
CFStringRef getValueForKey(CFDictionaryRef dict, CFStringRef key) {
CFStringRef value = NULL;
if (CFDictionaryContainsKey(dict, key)) {
value = CFDictionaryGetValue(dict, key);
}
return value;
}
ABRecordRef createPerson(CFDictionaryRef dict) {
ABRecordRef person = ABPersonCreate();
/*
Add work address ...
*/
ABMultiValueRef workAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSDictionary *values = [NSDictionary dictionaryWithObjectsAndKeys:
(NSString *)getValueForKey(dict, CFSTR("d:street")), (NSString *)kABPersonAddressStreetKey,
(NSString *)getValueForKey(dict, CFSTR("d:postalcode")), (NSString *)kABPersonAddressZIPKey,
(NSString *)getValueForKey(dict, CFSTR("d:l")), (NSString *)kABPersonAddressCityKey,
(NSString *)getValueForKey(dict, CFSTR("d:st")), (NSString *)kABPersonAddressCityKey,
(NSString *)getValueForKey(dict, CFSTR("d:co")), (NSString *)kABPersonAddressCountryKey,
nil];
multiValueAddDictionaryValueAndLabel(workAddress, (CFDictionaryRef)values, kABWorkLabel);
ABRecordSetValue(person, kABPersonAddressProperty, workAddress, NULL);
CFRelease(workAddress);
/*
Add home address ...
*/
ABMultiValueRef homeAddress = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
values = [NSDictionary dictionaryWithObjectsAndKeys:
(NSString *)getValueForKey(dict, CFSTR("d:homeStreet")), (NSString *)kABPersonAddressStreetKey,
(NSString *)getValueForKey(dict, CFSTR("d:homePostalCode")), (NSString *)kABPersonAddressZIPKey,
(NSString *)getValueForKey(dict, CFSTR("d:homeCity")), (NSString *)kABPersonAddressCityKey,
(NSString *)getValueForKey(dict, CFSTR("d:homeState")), (NSString *)kABPersonAddressCityKey,
(NSString *)getValueForKey(dict, CFSTR("d:homeCountry")), (NSString *)kABPersonAddressCountryKey,
nil];
multiValueAddDictionaryValueAndLabel(homeAddress, (CFDictionaryRef)values, kABHomeLabel);
ABRecordSetValue(person, kABPersonAddressProperty, homeAddress, NULL);
CFRelease(homeAddress);
}