Я добавляю несколько адресов в свою адресную книгу, но когда я пытаюсь вставить более одного адреса, как сначала, я вставляю рабочий адрес, а затем, если я вставляю домашний адрес, код вставит домашний адрес и удалит Рабочий адрес.
Вот мой код:
NSArray *mainComponents = [line componentsSeparatedByString:@":"];
NSArray *components = [[mainComponents objectAtIndex:1] componentsSeparatedByString:@";"];
if ([line rangeOfString:@"Work"].location != NSNotFound)
{
NSLog(@"Work--------");
ABMutableMultiValueRef multiOther = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary2 = [[NSMutableDictionary alloc] init];
NSString *otherStreetAddress=[NSString stringWithFormat:@"%@",[components objectAtIndex:0] ];
[addressDictionary2 setObject:otherStreetAddress forKey:(NSString *) kABPersonAddressStreetKey];
[addressDictionary2 setObject:[components objectAtIndex:2] forKey:(NSString *)kABPersonAddressStreetKey];
[addressDictionary2 setObject:[components objectAtIndex:3] forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary2 setObject:[components objectAtIndex:4] forKey:(NSString *)kABPersonAddressStateKey];
[addressDictionary2 setObject:[components objectAtIndex:5] forKey:(NSString *)kABPersonAddressZIPKey];
[addressDictionary2 setObject:[components objectAtIndex:6] forKey:(NSString *)kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(multiOther, addressDictionary2, kABWorkLabel, NULL);
[addressDictionary2 release];
ABRecordSetValue(personRecord, kABPersonAddressProperty,multiOther , NULL);// (personRecord, kABPersonAddressProperty, multiOther, NULL);
CFRelease(multiOther);
//ABAddressBookAddRecord(addressBook, personRecord, NULL);
}
else if ([line rangeOfString:@"HOME"].location != NSNotFound)
{
NSLog(@"Home0--------");
ABMutableMultiValueRef multiOther = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDictionary2 = [[NSMutableDictionary alloc] init];
NSString *otherStreetAddress=[NSString stringWithFormat:@"%@",[components objectAtIndex:0] ];
[addressDictionary2 setObject:otherStreetAddress forKey:(NSString *) kABPersonAddressStreetKey];
[addressDictionary2 setObject:[components objectAtIndex:2] forKey:(NSString *)kABPersonAddressStreetKey];
[addressDictionary2 setObject:[components objectAtIndex:3] forKey:(NSString *)kABPersonAddressCityKey];
[addressDictionary2 setObject:[components objectAtIndex:4] forKey:(NSString *)kABPersonAddressStateKey];
[addressDictionary2 setObject:[components objectAtIndex:5] forKey:(NSString *)kABPersonAddressZIPKey];
[addressDictionary2 setObject:[components objectAtIndex:6] forKey:(NSString *)kABPersonAddressCountryKey];
ABMultiValueAddValueAndLabel(multiOther, addressDictionary2, kABHomeLabel, NULL);
[addressDictionary2 release];
ABRecordSetValue(personRecord, kABPersonAddressProperty,multiOther , NULL);// (personRecord, kABPersonAddressProperty, multiOther, NULL);
CFRelease(multiOther);
}
ABAddressBookAddRecord (адресная книга, personRecord, NULL);
Как вставить более одного адреса?