0

我有这个代码来打开联系人视图控制器:

ABNewPersonViewController *newPersonVC = [[ABNewPersonViewController alloc] init];
               newPersonVC.newPersonViewDelegate = self;
               UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:newPersonVC];
               [self presentModalViewController:nc animated:YES];

我希望能够抓取NSString *phoneNumber = @"(416)-555-5555";并放入“家庭电话”领域。我查看 其他 答案,最终没有弹出任何内容或我的应用程序崩溃。苹果的文档也没有多大帮助。

我该如何解决这个问题?任何帮助表示赞赏。

4

1 回答 1

2
NSString *phoneNumber = @"(416)-555-5555";
ABRecordRef newPerson = ABPersonCreate();
CFErrorRef error = NULL;
ABRecordSetValue(newPerson, kABPersonDepartmentProperty,(__bridge  CFTypeRef)@"Department", nil);
ABMutableMultiValueRef phoneNumberMultiValue = ABMultiValueCreateMutable(kABPersonPhoneProperty);
ABMultiValueAddValueAndLabel(phoneNumberMultiValue,(__bridge  CFTypeRef)phoneNumber, kABWorkLabel, nil);
ABRecordSetValue(newPerson, kABPersonPhoneProperty, phoneNumberMultiValue, nil);
NSAssert( !error, @"Something bad happened here." );

ABNewPersonViewController *newPersonVC = [[ABNewPersonViewController alloc] init];
[newPersonVC setDisplayedPerson:newPerson];
newPersonVC.newPersonViewDelegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:newPersonVC];
[self presentModalViewController:nc animated:YES];

希望它对你有帮助。

于 2012-11-15T12:50:07.770 回答