开发者

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.na开发者_如何学运维vigationItem.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.

Address Book Programming Guide for iPhone - QuickStart

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.


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


ABPerson function [ABAddressBookCopyArrayOfAllPeople] will work here.

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜