0

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

WhatsApp messenger 是一个很棒的例子,如果你去设置,告诉朋友,然后消息.. 我想要那个样子!

联系人 Pickerview 它必须是自定义的,因为我还想要下面的发送和取消按钮,以及 cell.textLabel 中的名称及其在 subtitle 样式表视图中 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];
}
4

2 回答 2

2

你可以通过下面的代码从地址簿中得到你想要的东西我的朋友。!!!!!!

编码快乐!!!!!!

- (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);
}
}
于 2012-12-11T09:56:12.623 回答
0

要获取电话号码...

ABMultiValueRef phoneNumbers = ABRecordCopyValue(person, kABPersonPhoneProperty); 
 NSString*    phone = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0); 

 nslog(@"phone:%@",phone); 

让我知道它是否有效!!!!!!请如果它是正确的然后奖励它,我知道它是正确的..

快乐编码

于 2012-12-11T12:48:30.240 回答