简体   繁体   English

如何将联系人列表从 iphone 通讯录导入到我的应用程序?

[英]how to import contact list from iphone address book to my application?

- (void)viewDidLoad {
    [super viewDidLoad];

    // Uncomment the following line to display an Edit button in the navigation bar for this view controller.

    UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"2.png"] style:UIBarButtonItemStyleBordered target:self action:nil];
    self.navigationItem.rightBarButtonItem = btn;

    self.navigationItem.title = @"Contacts";

    sBar = [[UISearchBar alloc]initWithFrame:CGRectMake(0,0,320,30)];
    sBar.delegate = self;

    [self.view addSubview:sBar];
    sBar.placeholder=@"Search";


    searchedData = [[NSMutableArray alloc]init];

    tableData = [[NSMutableArray alloc]init];

    [tableData addObjectsFromArray:dataSource]; 
}

The following Quick Start guide from Apple's iOS docs could get you started on this.以下来自 Apple 的 iOS 文档的快速入门指南可以帮助您开始。

Address Book Programming Guide for iPhone - QuickStart iPhone 通讯簿编程指南 - 快速入门

It shows you how to import the AddressBookUI/AddressBookUI.h headers and open a native people picker, as well as listen for when a person is picked.它向您展示了如何导入AddressBookUI/AddressBookUI.h标头并打开本地人员选择器,以及在选择人员时进行监听。

You will need to implement the following table delegate method to actually get your table to display data.您将需要实现以下表格委托方法才能真正让您的表格显示数据。

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

You can find more documentation on UITableView here您可以在此处找到有关UITableView的更多文档

ABPerson function [ABAddressBookCopyArrayOfAllPeople] will work here. ABPerson function [ABAddressBookCopyArrayOfAllPeople] 将在这里工作。

ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

for ( int i = 0; i < nPeople; i++ )
{
    ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );
    ...
}

After fetching the array of npeople you can display it in your tableView or do whatever you want to implement.获取 npeople 数组后,您可以在 tableView 中显示它或执行任何您想要实现的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM