1

ここで、Webアレイから新しい連絡先番号を追加しようとしていますが、デバイスにデータが入力されていません

CNLabeledValue *homePhone = [CNLabeledValue labeledValueWithLabel:CNLabelPhoneNumberMobile value:[CNPhoneNumber phoneNumberWithStringValue:[NSString stringWithFormat:@"%@",[[contactDict valueForKey:@"Mobile"]objectAtIndex:i]]]];

        contact.phoneNumbers = @[homePhone];
CNSaveRequest *request = [[CNSaveRequest alloc] init];
        [request addContact:contact toContainerWithIdentifier:nil];
4

1 に答える 1

1

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)
}
于 2016-03-11T11:20:05.717 に答える