gpt4 book ai didi

iphone - 自定义地址簿 ABPeoplePickerViewController 帮忙吗?

转载 作者:行者123 更新时间:2023-11-28 22:43:37 24 4
gpt4 key购买 nike

我需要有关 iPhone 的自定义地址簿 (ABPeoplePickerViewController) 的帮助吗?我想要一个包含我所有联系人的数组,只将他们的姓名和号码拉到表格 View 的单元格中以显示。选择几个联系人,打开消息并向他们发送带有自定义消息的文本/短信。

WhatsApp Messenger 是一个很棒的例子,如果您转到“设置”,“告诉 friend ”,然后“消息”..我想要那个样子!

Contacts Pickerview它必须是自定义的,因为我还想要下面的“发送”和“取消”按钮,以及 cell.textLabel 中的名称及其在字幕样式 TableView 中的 cell.detailTextLabel 中的编号。

那么我如何从地址簿中获取他们的详细信息并将其放入我的数组(contactsName、contactsNumber)中?提前致谢!这是我的代码:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [_tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}

cell.textLabel.text = [contactsName objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [contactsNumber objectAtIndex:indexPath.row];

return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
}

- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker
{
[self dismissViewControllerAnimated:YES completion:^{ NSLog(@"Message controller has been canceled"); }];
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person
{
NSString *name = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonFirstNameProperty);
NSString *number = (__bridge_transfer NSString*)ABRecordCopyValue(person, kABPersonPhoneProperty);
NSLog(@"Name: %@ Number: %@", name, number);

return NO;
}

- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier
{
return NO;
}

- (void)openSMScontroller {
MFMessageComposeViewController *smsView = [[MFMessageComposeViewController alloc] init];
smsView.messageComposeDelegate = self;

smsView.recipients = [NSArray arrayWithArray:contactsNumber];
smsView.body = @"Check out this awesome app!";

[self presentModalViewController:smsView animated:YES];
}

最佳答案

我的 friend ,你可以通过下面的代码从地址簿中获取你想要的内容。!!!!!

快乐编码!!!!!!

- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {
ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty);
ABMultiValueRef addressProperty = ABRecordCopyValue(person, kABPersonAddressProperty);
NSArray *address = (NSArray *)ABMultiValueCopyArrayOfAllValues(addressProperty);
if([address count] > 0)
{
for (NSDictionary *addressDict in address)
{
countrytf.text = [addressDict objectForKey:@"Country"];
streetaddresstf.text = [addressDict objectForKey:@"Street"];
citynametf.text = [addressDict objectForKey:@"City"];
statenametf.text = [addressDict objectForKey:@"State"];
zipcodetf.text = [addressDict objectForKey:@"ZIP"];

}
CFRelease(addressProperty);
}
}

关于iphone - 自定义地址簿 ABPeoplePickerViewController 帮忙吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13817370/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com