Objective-C
// create contact
CNMutableContact *contact = [[CNMutableContact alloc] init];
contact.familyName = @"Doe";
contact.givenName = @"John";
// Add mobile number
CNLabeledValue *mobileNumber = [CNLabeledValue labeledValueWithLabel: CNLabelPhoneNumberMobile value:[CNPhoneNumber phoneNumberWithStringValue:@"123-123-1212"]];
contact.phoneNumbers = @[mobileNumber];
CNSaveRequest *request = [[CNSaveRequest alloc] init];
[request addContact:contact toContainerWithIdentifier:nil];
// save contact
NSError *saveError;
if (![store executeSaveRequest:request error:&saveError]) {
NSLog(@"error = %@", saveError);
}
迅速
// create contact
var contact: CNMutableContact = CNMutableContact()
contact.familyName = "Doe"
contact.givenName = "John"
// Add mobile number
var mobileNumber: CNLabeledValue = CNLabeledValue.labeledValueWithLabel(CNLabelPhoneNumberMobile, value: CNPhoneNumber.phoneNumberWithStringValue("123-123-1212"))
contact.phoneNumbers = [mobileNumber]
var request: CNSaveRequest = CNSaveRequest()
request.addContact(contact, toContainerWithIdentifier: nil)
// save contact
NSError * saveError
if !store.executeSaveRequest(request, error: saveError) {
NSLog("error = %@", saveError)
}