CNContact框架phonenumbers存储空白

时间:2016-03-11 11:11:18

标签: ios objective-c cncontact cncontactstore

这里我试图从网络阵列添加新的联系号码,并且设备中没有数据输入

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];

1 个答案:

答案 0 :(得分:1)

<强>目标C

~4.8GB RAM

<强>夫特

// 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);
}