Access the Address Book
来源:互联网 发布:菜谱录入软件 编辑:程序博客网 时间:2024/05/23 02:05
Access the Address Book
I got a request on how do I access the address book in the iPhone. So I took around 30 minutes to learn how and here is how we will do it.
First create a new View-Based Application and call it addressBook.
Now the first thing we want to do is setup the 4 IBOutlets and the 1 IBAction for our project. We also need to include the headers for the address book framework. So open up addressBookViewController.h and you want to make it look like the following.
#import <UIKit/UIKit.h>#import <AddressBook/AddressBook.h>#import <AddressBookUI/AddressBookUI.h>@interface addressBookViewController : UIViewController {IBOutlet UIButton *button;IBOutlet UILabel *firstName;IBOutlet UILabel *lastName;IBOutlet UILabel *number;}-(IBAction)getContact;@end
Now that they are added we need to add in the framework files. So you will right click on the addressBook in the Targets option on the left panel and click on Get Info.
At the bottom there is a + and click that and you need to add the following items in AddressBook.framework and AddressBookUI.framework
Now lets layout our view. So double click on addressBookViewController.xib. You want your view to look like the following.
I used the —–’s just so you can see there is a UILabel there. Now we need to setup the connections for the 4 outlets and the one action. You want it to look like the following
So now lets open up addressBookViewController.m and we want to add in the following methods.
-(IBAction)getContact {// creating the pickerABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];// place the delegate of the picker to the controllpicker.peoplePickerDelegate = self;// showing the picker[self presentModalViewController:picker animated:YES];// releasing[picker release];}- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker { // assigning control back to the main controller[self dismissModalViewControllerAnimated:YES];}- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {// setting the first name firstName.text = (NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty);// setting the last name lastName.text = (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);// setting the number/* this function will set the first number it finds if you do not set a number for a contact it will probably crash */ABMultiValueRef multi = ABRecordCopyValue(person, kABPersonPhoneProperty);number.text = (NSString*)ABMultiValueCopyValueAtIndex(multi, 0);// remove the controller [self dismissModalViewControllerAnimated:YES]; return NO;}- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{ return NO;}
Now we can click build and go and see the following
- Access the Address Book
- Address Book
- resolve the address to the Access database
- iPhone Programming: Adding a Contact to the iPhone Address Book
- Address book 优先级
- IOS编程:Address Book
- [iOS] contact address book
- Address Book(地址薄)
- ios address book
- address book api 图型
- Supplier Address Book
- The Address Book does not contain a cross certificate capable of validating the public key
- 学习iphone - address book recorder
- Dynamics ax global address book
- ios address book 操作大全
- iOS Address Book编程指南
- Address Book UI 框架 浅析
- ios address book 操作大全
- Integrating ISA Server 2006 with Microsoft Exchange 2007
- BindingSource的使用范例
- JRuby Cookbook
- mysql物理备份
- Winning with Software: An Executive Strategy
- Access the Address Book
- Next Generation Wireless LANs: Throughput, Robustness, and Reliability in 802.11n
- Web Application和Chromium
- WiMedia UWB: Technology of Choice for Wireless USB and Bluetooth
- mysql 如何修改字符集
- SQL多条件查询语句
- 批量修改数据库某字段内容
- 使用ASP.NET上传多个文件到服务器
- 做项目的体会