Skip to content

Instantly share code, notes, and snippets.

@fernyb
Created February 24, 2011 17:03
Show Gist options
  • Save fernyb/842453 to your computer and use it in GitHub Desktop.
Save fernyb/842453 to your computer and use it in GitHub Desktop.
Creating a new person with AddressBook.framework
ABPerson * newPerson = [[ABPerson alloc] init];
[newPerson setValue:@"John" forProperty:kABFirstNameProperty];
[newPerson setValue:@"Doe" forProperty:kABLastNameProperty];
ABMutableMultiValue * values = [[ABMutableMultiValue alloc] init];
[values addValue:@"example@example.com" withLabel:kABOtherLabel];
[newPerson setValue:values forProperty:kABEmailProperty];
[[ABAddressBook sharedAddressBook] addRecord:newPerson];
if ( [[ABAddressBook sharedAddressBook] save] ) {
NSString * addrbookUrl = [NSString stringWithFormat:@"addressbook://%@?edit", [newPerson uniqueId]];
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:addrbookUrl]];
}
[values release];
[newPerson release];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment