如何向iPhone中已存在的联系人添加信息?
我已经处理过这些信息,但我还没想出如何向现有联系人添加信息。
ABUnknownPersonViewController *unknownPersonViewController = [[ABUnknownPersonViewController alloc] init];
unknownPersonViewController.displayedPerson = (ABRecordRef)[self buildContactDetails];
unknownPersonViewController.allowsAddingToAddressBook = YES;
[self.navigationController pushViewController:unknownPersonViewController animated:YES];
[unknownPersonViewController release];
- (ABRecordRef)buildContactDetails {
NSLog(@"building contact details");
ABRecordRef person = ABPersonCreate();
CFErrorRef error = NULL;
// firstname
int i ; int taille ;
taille = [carte.informations count];
NSString *nom=nil ;
NSString *adresse=nil ;
NSString *mail=nil,*prenom=nil,*tel=nil,*societe=nil,*profession=nil;
for (i=0; i<taille; i++) {
if ([(Information*)[self.carte.informations objectAtIndex:i] label]==1) {
nom = [(Information*)[self.carte.informations objectAtIndex:i] content];
}
else if([(Information*)[self.carte.informations objectAtIndex:i] label]==2) {
prenom=[(Information*)[self.carte.informations objectAtIndex:i] content];
}
else if([(Information*)[self.carte.informations objectAtIndex:i] label]==3){
tel=[(Information*)[self.carte.informations objectAtIndex:i] content];
}
else if([(Information*)[self.carte.informations objectAtIndex:i] label]==4){
societe=[(Information*)[self.carte.informations objectAtIndex:i] content];
}
else if([(Information*)[self.carte.informations objectAtIndex:i] label]==5) {
adresse = [(Information*)[self.carte.informations objectAtIndex:i] content];
}
else if ([(Information*)[self.carte.informations objectAtIndex:i] label]==6){
mail = [(Information*)[self.carte.informations objectAtIndex:i] content];
}
else if ([(Information*)[self.carte.informations objectAtIndex:i] label]==7){
profession = [(Information*)[self.carte.informations objectAtIndex:i] content];
}
}
if(nom != nil && (![nom isEqualToString:@""])){
ABRecordSetValue(person, kABPersonFirstNameProperty,nom, NULL);
}
if (prenom != nil && (![prenom isEqualToString:@""])) {
ABRecordSetValue(person, kABPersonLastNameProperty, prenom, NULL);
}
if(mail != nil && (![mail isEqualToString:@""])){
ABMutableMultiValueRef email = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(email, mail, CFSTR("email"), NULL);
ABRecordSetValue(person, kABPersonEmailProperty, email, &error);
CFRelease(email);
}
//Phone
if(tel != nil && (![tel isEqualToString:@""])){
ABMutableMultiValueRef Phone = ABMultiValueCreateMutable(kABMultiStringPropertyType);
ABMultiValueAddValueAndLabel(Phone, tel, CFSTR("Phone"), NULL);
ABRecordSetValue(person,kABPersonPhoneProperty, Phone, &error);
CFRelease(Phone);
}
if(adresse != nil && (![adresse isEqualToString:@""])){
// Start of Address
ABMutableMultiValueRef address = ABMultiValueCreateMutable(kABMultiDictionaryPropertyType);
NSMutableDictionary *addressDict = [[NSMutableDictionary alloc] init];
[addressDict setObject:adresse forKey:(NSString *)kABPersonAddressStreetKey];
//[addressDict setObject:@"0568" forKey:(NSString *)kABPersonAddressZIPKey];
//[addressDict setObject:@"Oslo" forKey:(NSString *)kABPersonAddressCityKey];
ABMultiValueAddValueAndLabel(address, addressDict, kABWorkLabel, NULL);
ABRecordSetValue(person, kABPersonAddressProperty, address, &error);
[addressDict release];
CFRelease(address);
// End of Address
}
if (error != NULL)
NSLog(@"Error: %@", error);
[(id)person autorelease];
return person;
}
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(ABRecordRef)person{}
我在这个示例中已经这样做,我可以添加一个新的联系人与我的信息,但我不能为现有的联系人添加信息