我有这段代码打开联系人视图控制器:
ABNewPersonViewController *newPersonVC = [[ABNewPersonViewController alloc] init];
newPersonVC.newPersonViewDelegate = self;
UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:newPersonVC];
[self presentModalViewController:nc animated:YES];
我希望能够抓住NSString *phoneNumber = @"(416)-555-5555";
并将其放入“家庭电话”字段。我查看了through other answers,我最终没有弹出任何内容或我的应用崩溃了。 Apple的文档也没有多大帮助。
我该如何解决这个问题?任何帮助表示赞赏。
答案 0 :(得分: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];
希望它对你有帮助。