using the addressbook
DESCRIPTION
Collin Donnell - Using the Addressbook. Non Game App Dev Track. 360|iDev San Jose '09TRANSCRIPT
![Page 1: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/1.jpg)
Using The Address Book
or: How I Learned To Stop Worrying And Love The Address Book
Tuesday, March 3, 2009
![Page 2: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/2.jpg)
Why use the Address Book?
• Using the address book gives you an easy way to access and use data your users already have.
• Make up for things Contacts can’t do.
• Extend what your existing application can do.
Tuesday, March 3, 2009
![Page 3: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/3.jpg)
Two Frameworks
• AddressBook allows for direct manipulation of the address book.
• AddressBookUI Set of view controllers which allow picking, adding new, editing, or viewing contacts.
Tuesday, March 3, 2009
![Page 4: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/4.jpg)
AddessBook
• Four basic data types: Address books, Records, Single-value properties, and Multivalue properties.
• C based, follows Core Foundation rules for memory management.
Tuesday, March 3, 2009
![Page 5: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/5.jpg)
Address Books
• Stored as an ABAddressBookRef.
• Used to get information about and edit the address book directly.
• One per thread.
• Changes must be saved.
Tuesday, March 3, 2009
![Page 6: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/6.jpg)
AddressBook Functions
•ABAddressBookCreate: Create a new address book.
•ABAddressBookSave: Commit any changes that you’ve made to the address book.
•ABAddressBookRevert: Throw away unsaved changes.
•ABAddressBookAddRecord: Add or remove a record from the address book. Both take an ABRecordRef.
•ABAddressBookRegisterExternalCallBack: Use to receive a call when the address book is changed by another app, or another thread in your app.
Tuesday, March 3, 2009
![Page 7: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/7.jpg)
Records• Both people and groups are stored as ABRecordRef’s.
• Find out the type by using the function ABRecordGetRecordType, which returns an kABGroupType or kABPersonType.
• Do not pass a record address threads, ask for the records identifier and use that instead.
• Use ABRecordGetRecordID to get the unique ID from a group or person record.
• ABRecordCopyValue, ABRecordSetValue, ABRecordRemoveValue are used to copy, set, or remove values from records.
Tuesday, March 3, 2009
![Page 8: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/8.jpg)
Group Records
• ABGroupCreate
• ABGroupCopyArrayOfAllMembers
• ABGroupCopyArrayOfAllMembersWithSortOrdering
• ABGroupAddRecord, and ABGroupRemoveRecord
• ABAddressBookCopyArrayOfAllMembers
Tuesday, March 3, 2009
![Page 9: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/9.jpg)
Person Records• ABPersonCreate
• ABPersonGetTypeOfProperty
• ABPersonCopyLocalizedPropertyName
• ABPersonHasImageData, ABPersonCopyImageData, ABPersonRemoveImageData, and ABPersonSetImageData
• ABAddressBookComparePeopleByName
• ABAddressBookCopyPeopleWithName
Tuesday, March 3, 2009
![Page 10: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/10.jpg)
Person PropertieskABPersonFirstNamePropertykABPersonLastNamePropertykABPersonMiddleNamePropertykABPersonPrefixPropertykABPersonSuffixPropertykABPersonNicknamePropertykABPersonFirstNamePhoneticPropertykABPersonLastNamePhoneticPropertykABPersonMiddleNamePhoneticPropertykABPersonOrganizationPropertykABPersonJobTitlePropertykABPersonDepartmentPropertykABPersonEmailPropertykABPersonBirthdayPropertykABPersonNotePropertykABPersonCreationDatePropertykABPersonModificationDatePropertykABPersonAddressProperty
Tuesday, March 3, 2009
![Page 11: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/11.jpg)
Displaying Names
• ABRecordCopyCompositeName will return a string for a group or person record with the correct formatting.
• ABPersonCompositeNameFormat can be used to determine first name or last name first name format.
• ABPersonGetSortOrdering tells if people records should be sorted by first or last name.
Tuesday, March 3, 2009
![Page 12: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/12.jpg)
Getting Records• ABAddressBookGetGroupWithRecordID &
ABAddressBookGetPersonWithRecordID are used to get group or person records when you have the ID.
• You can ask the how many people or groups there are by using ABAddressBookGetGroupCount & ABAddressBookGetPersonCount
• ABAddressBookCopyArrayOfAllGroups
• ABAddressBookCopyArrayOfAllPeople
Tuesday, March 3, 2009
![Page 13: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/13.jpg)
Single Value Properties
• Pass a property name and a value.
• Example:
ABRecordSetValue(person, kABPersonFirstNameProperty, CFSTR(“First Name”), &error);
Tuesday, March 3, 2009
![Page 14: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/14.jpg)
Example!#import <AddressBook/AddressBook.h>
Tuesday, March 3, 2009
![Page 15: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/15.jpg)
Multivalueproperties
• Things like phone numbers, email addresses, where a single contact may have multiple.
• List of values, each of which has a text label and an identifier.
• Functions used to read are, ABMultiValueCopyLabelAtIndex ABMultiValueCopyValueAtIndex ABMultiValueCopyArrayOfAllValues ABMultiValueGetIndexForIdentifier ABMultiValueGetIdentifierAtIndex
Tuesday, March 3, 2009
![Page 16: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/16.jpg)
Mutable MultivalueProperties
• ABMultiValueCreateMutableCopy to create a mutable copy of a multivalue property.
• ABMultiValueCreateMutable to construct your own.
• Functions for editing mutable multivalue properties ABMultiValueAddValueAndLabel ABMultiValueInsertValueAndLabelAtIndex ABMultiValueReplaceValueAtIndex ABMultiValueRemoveValueAndLabelAtIndex
Tuesday, March 3, 2009
![Page 17: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/17.jpg)
Another Example!
Tuesday, March 3, 2009
![Page 18: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/18.jpg)
Street Addresses
• Multivalue of dictionaries.
• Each address component is a key/value pair.
Tuesday, March 3, 2009
![Page 19: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/19.jpg)
Street AddressExample
Tuesday, March 3, 2009
![Page 20: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/20.jpg)
AddressBookUI
• View controllers for many common address book related functions.
• 4 controllers:
• ABPeoplePickerNavigationController
• ABPersonViewController
• ABNewPersonViewController
• ABUnknownPersonViewController
Tuesday, March 3, 2009
![Page 21: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/21.jpg)
Picking People• ABPeoplePickerNavigationController
presents a very similar view to Contacts.
• Present as a modal view controller and implement the delegate methods.
ABPeoplePickerNavigationControllerDelegate Methods
peoplePickerNavigationControllerDidCancel:
peoplePickerNavigationController:shouldContinueAfterSelectingPerson:
peoplePickerNavigationController:shouldContinueAfterSelectingPerson:property:identifier:
Tuesday, March 3, 2009
![Page 22: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/22.jpg)
Viewing/Editing Person Records
• ABPersonViewController will display and allow editing of person records.
• Will call personViewController:shouldPerformDefaultActionForPerson:property:identifier:
On its delegate when the user taps a property.
Tuesday, March 3, 2009
![Page 23: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/23.jpg)
Creating NewPerson Records
• ABNewPersonViewController allows users to create new people and add them to the database with almost no code.
• When finished, it will call newPersonViewController:didCompleteWithNewPerson:
Tuesday, March 3, 2009
![Page 24: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/24.jpg)
Unknown PersonController
• Add to or create a new person with existing data.
• Create person with known information, use setDisplayedPerson:
• Will call unknownPersonViewController:didResolveToPerson: on it’s delegate when finished.
Tuesday, March 3, 2009
![Page 25: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/25.jpg)
Loading...
Tuesday, March 3, 2009
![Page 26: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/26.jpg)
Using
Tuesday, March 3, 2009
![Page 27: Using the Addressbook](https://reader033.vdocument.in/reader033/viewer/2022060110/555a0a4dd8b42a76498b45b5/html5/thumbnails/27.jpg)
Contact Me
• Collin Donnell (iPhone Developer)
• Email: [email protected]
• Twitter: collindonnell
Tuesday, March 3, 2009