这个方法在iOS9之后被弃用了,因为我要适配老版本的系统,所以还要使用这个。
具体代码如下:
- (void)saveNewPersonConnectWithName:(NSString *)name companyName:(NSString *)companyName mobile:(NSString *)mobile viewController:(UIViewController *)viewController delegate:(id)delegate
{
ABNewPersonViewController *picker = [[ABNewPersonViewController alloc] init];
ABRecordRef newPerson = ABPersonCreate();
ABMutableMultiValueRef multiValue = ABMultiValueCreateMutable(kABMultiStringPropertyType | kABMultiIntegerPropertyType);
CFErrorRef error = NULL;
//添加手机号
ABMultiValueAddValueAndLabel(multiValue, (__bridge CFTypeRef)(mobile), kABPersonPhoneMobileLabel, NULL);
//添加姓名
// ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFTypeRef)(_lastNameFiled.text), &error);
ABRecordSetValue(newPerson, kABPersonFirstNameProperty, (__bridge CFTypeRef)(name), &error);
//添加公司名称
ABRecordSetValue(newPerson, kABPersonOrganizationProperty, (__bridge CFTypeRef)(companyName), &error);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, multiValue , &error);
CFRelease(multiValue);
picker.displayedPerson = newPerson;
CFRelease(newPerson);
picker.newPersonViewDelegate = delegate;
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:picker];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[viewController presentViewController:nav animated:YES completion:nil];
}];
}
- (void)newPersonViewController:(ABNewPersonViewController *)newPersonView didCompleteWithNewPerson:(nullable ABRecordRef)person
{
[self dismissViewControllerAnimated:YES completion:nil];
NSLog(@"%@-\n-%@",newPersonView,person);
}
可以根据自己的需要,来进行定制,比如添加Email QQ等联系人信息。有不懂的可以留言,代码不足之处,敬请各位指出来,谢谢了。