CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting...
Transcript of CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting...
![Page 1: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/1.jpg)
CS193P - Lecture 13iPhone Application Development
Address Book - Putting People in Your App
1Tuesday, February 16, 2010
![Page 2: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/2.jpg)
Announcements• Paparazzi 3 due tomorrow at 11:59PM• Paparazzi 4 (last assignment!) due next Wednesday
2Tuesday, February 16, 2010
![Page 3: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/3.jpg)
Final Project Proposals• Due tomorrow night!
■ Handout on website has all the info
• If you still need an idea for a project, let us know• We will be responding with feedback & a thumbs-up
3Tuesday, February 16, 2010
![Page 4: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/4.jpg)
• Address Book APIs• CoreFoundation• Merging from an external source of people• Using contacts in your application
Today’s Topics
4Tuesday, February 16, 2010
![Page 5: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/5.jpg)
Putting Contacts in Your AppThe Hello World of Address Book
5Tuesday, February 16, 2010
![Page 6: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/6.jpg)
The Hello World of Address Book• Create a person and set some properties• Create ABPersonViewController• Push the view controller onto the navigation stack
6Tuesday, February 16, 2010
![Page 7: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/7.jpg)
CoreFoundation
7Tuesday, February 16, 2010
![Page 8: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/8.jpg)
CoreFoundation vs. Foundation
8Tuesday, February 16, 2010
![Page 9: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/9.jpg)
CoreFoundation vs. Foundation• CoreFoundation is a framework written in C
8Tuesday, February 16, 2010
![Page 10: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/10.jpg)
CoreFoundation vs. Foundation• CoreFoundation is a framework written in C• Many parallels to Foundation
■ CFDictionaryRef, CFStringRef■ CFRetain, CFRelease
8Tuesday, February 16, 2010
![Page 11: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/11.jpg)
CoreFoundation vs. Foundation• CoreFoundation is a framework written in C• Many parallels to Foundation
■ CFDictionaryRef, CFStringRef■ CFRetain, CFRelease
• AddressBook framework is also C-based■ Uses CoreFoundation data types and semantics
8Tuesday, February 16, 2010
![Page 12: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/12.jpg)
CoreFoundation vs. Foundation• CoreFoundation is a framework written in C• Many parallels to Foundation
■ CFDictionaryRef, CFStringRef■ CFRetain, CFRelease
• AddressBook framework is also C-based■ Uses CoreFoundation data types and semantics
• Addition to memory management naming conventions■ Functions with Create in their title return a retained object■ For example, ABAddressBookCreate( );
8Tuesday, February 16, 2010
![Page 13: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/13.jpg)
Toll-Free Bridging• Supported for many types of objects
■ Strings, arrays, dictionaries, dates, numbers, data streams, more
• Use an NSString* where a CFStringRef is expected & vice versa• Very convenient for mixing & matching C with Objective-C
9Tuesday, February 16, 2010
![Page 14: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/14.jpg)
Toll-Free Bridging• Supported for many types of objects
■ Strings, arrays, dictionaries, dates, numbers, data streams, more
• Use an NSString* where a CFStringRef is expected & vice versa• Very convenient for mixing & matching C with Objective-C
CFArrayRef array = ABAddressBookCopyPeopleWithName(...);
NSLog(@“%d”, [(NSArray *)array count]);
NSMutableArray *mutableArray = [(NSArray *)array mutableCopy];[mutableArray release];
if (array) {CFRelease(array);
}
9Tuesday, February 16, 2010
![Page 15: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/15.jpg)
CoreFoundation and NULL
10Tuesday, February 16, 2010
![Page 16: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/16.jpg)
CoreFoundation and NULL• Unlike Objective-C, must NULL-check CF type objects
10Tuesday, February 16, 2010
![Page 17: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/17.jpg)
CoreFoundation and NULL• Unlike Objective-C, must NULL-check CF type objects
■ (Since nil is typed id, we use NULL for CF)
10Tuesday, February 16, 2010
![Page 18: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/18.jpg)
CoreFoundation and NULL• Unlike Objective-C, must NULL-check CF type objects
■ (Since nil is typed id, we use NULL for CF)
CFStringRef string = CreateSomeCFString...;if (string != NULL) {
DoSomethingWith(string);CFRelease(string);
}
10Tuesday, February 16, 2010
![Page 19: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/19.jpg)
CoreFoundation and NULL• Unlike Objective-C, must NULL-check CF type objects
■ (Since nil is typed id, we use NULL for CF)
■ Toll-free bridging can make this easier
CFStringRef string = CreateSomeCFString...;if (string != NULL) {
DoSomethingWith(string);CFRelease(string);
}
10Tuesday, February 16, 2010
![Page 20: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/20.jpg)
CoreFoundation and NULL• Unlike Objective-C, must NULL-check CF type objects
■ (Since nil is typed id, we use NULL for CF)
■ Toll-free bridging can make this easier
CFStringRef string = CreateSomeCFString...;if (string != NULL) {
DoSomethingWith(string);CFRelease(string);
}
NSString *string = (NSString *)CreateSomeCFString...;NSLog(@“%@”, [string lowercaseString]);[string autorelease]; // Even use autorelease!
10Tuesday, February 16, 2010
![Page 21: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/21.jpg)
Beyond Hello World
11Tuesday, February 16, 2010
![Page 22: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/22.jpg)
Social Networking Website
12Tuesday, February 16, 2010
![Page 23: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/23.jpg)
Social Networking Website• People on the web
12Tuesday, February 16, 2010
![Page 24: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/24.jpg)
Social Networking Website• People on the web• People on the iPhone
12Tuesday, February 16, 2010
![Page 25: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/25.jpg)
Social Networking Website• People on the web• People on the iPhone• Reconciling them
12Tuesday, February 16, 2010
![Page 26: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/26.jpg)
What Do We Need to Do?
13Tuesday, February 16, 2010
![Page 27: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/27.jpg)
What Do We Need to Do?• Download
13Tuesday, February 16, 2010
![Page 28: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/28.jpg)
What Do We Need to Do?• Download
• Search
13Tuesday, February 16, 2010
![Page 29: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/29.jpg)
What Do We Need to Do?• Download
• Search
• Update
13Tuesday, February 16, 2010
![Page 30: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/30.jpg)
What Do We Need to Do?• Download
• Search
• Update
• Display
13Tuesday, February 16, 2010
![Page 31: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/31.jpg)
Search• Get the address book• Search the people
Step One
14Tuesday, February 16, 2010
![Page 32: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/32.jpg)
Search• Get the address book• Search the people
ABAddressBookRef ab = ABAddressBookCreate();CFArrayRef people = ABAddressBookCopyPeopleWithName(ab, name);
Step One
14Tuesday, February 16, 2010
![Page 33: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/33.jpg)
Address Book• ABAddressBookRef• Gives you access to the people• Central point for all things address book• Multiple instances, a single database
ABAddressBookRef ab = ABAddressBookCreate();
15Tuesday, February 16, 2010
![Page 34: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/34.jpg)
Person• ABRecordRef• A collection of properties
■ First and last name■ Image■ Phone numbers, emails, etc…
16Tuesday, February 16, 2010
![Page 35: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/35.jpg)
• Properties can have different types■ String■ Date■ Dictionary, Data…
• Some properties may have multiple values■ Telephone: home, work, mobile, fax…
• Person properties in ABPerson.h
Properties
17Tuesday, February 16, 2010
![Page 36: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/36.jpg)
• First Name, last name, birthday, etc…
• CoreFoundation types
Single Value Properties
18Tuesday, February 16, 2010
![Page 37: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/37.jpg)
• First Name, last name, birthday, etc…
• CoreFoundation types
• Retrieve values with ABRecordCopyValue(…)
Single Value Properties
18Tuesday, February 16, 2010
![Page 38: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/38.jpg)
• First Name, last name, birthday, etc…
• CoreFoundation types
• Retrieve values with ABRecordCopyValue(…)
Single Value Properties
CFStringRef first = ABRecordCopyValue(person, kABPersonFirstNameProperty);
18Tuesday, February 16, 2010
![Page 39: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/39.jpg)
• First Name, last name, birthday, etc…
• CoreFoundation types
• Retrieve values with ABRecordCopyValue(…)
• Set values with ABRecordSetValue(…)
Single Value Properties
CFStringRef first = ABRecordCopyValue(person, kABPersonFirstNameProperty);
18Tuesday, February 16, 2010
![Page 40: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/40.jpg)
• First Name, last name, birthday, etc…
• CoreFoundation types
• Retrieve values with ABRecordCopyValue(…)
• Set values with ABRecordSetValue(…)
Single Value Properties
CFStringRef first = ABRecordCopyValue(person, kABPersonFirstNameProperty);
CFDateRef date = CFDateCreate(…)ABRecordSetValue(person, kABPersonBirthdayProperty, date, &error);
18Tuesday, February 16, 2010
![Page 41: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/41.jpg)
• Phones, emails, URLs, etc…
• Access just like single value properties
• ABMultiValueRef
• Container for values and labels
Multi Value Properties
label: kABHomeLabelvalue: (408) 555 1234
label: kABWorkLabelvalue: (408) 555 2345
ABMultiValueRefproperty:kABPersonPhoneProperty
label: kABHomeLabelvalue: (415) 555 2375
19Tuesday, February 16, 2010
![Page 42: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/42.jpg)
ABMultiValueRef
20Tuesday, February 16, 2010
![Page 43: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/43.jpg)
• Count
ABMultiValueRef
20Tuesday, February 16, 2010
![Page 44: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/44.jpg)
• Count
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
20Tuesday, February 16, 2010
![Page 45: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/45.jpg)
• Count
• Value
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
20Tuesday, February 16, 2010
![Page 46: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/46.jpg)
• Count
• Value
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
CFTypeRef value = ABMultiValueCopyValueAtIndex(mv, index);
20Tuesday, February 16, 2010
![Page 47: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/47.jpg)
• Count
• Value
• Label
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
CFTypeRef value = ABMultiValueCopyValueAtIndex(mv, index);
20Tuesday, February 16, 2010
![Page 48: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/48.jpg)
• Count
• Value
• Label
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
CFTypeRef value = ABMultiValueCopyValueAtIndex(mv, index);
CFStringRef label = ABMultiValueCopyLabelAtIndex(mv, index);
20Tuesday, February 16, 2010
![Page 49: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/49.jpg)
• Count
• Value
• Label
• Identifier
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
CFTypeRef value = ABMultiValueCopyValueAtIndex(mv, index);
CFStringRef label = ABMultiValueCopyLabelAtIndex(mv, index);
20Tuesday, February 16, 2010
![Page 50: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/50.jpg)
• Count
• Value
• Label
• Identifier
ABMultiValueRef
CFIndex count = ABMultiValueGetCount(multiValue);
CFTypeRef value = ABMultiValueCopyValueAtIndex(mv, index);
CFStringRef label = ABMultiValueCopyLabelAtIndex(mv, index);
CFIndex identifier = ABMultiValueGetIdentifierAtIndex(mv, index);
20Tuesday, February 16, 2010
![Page 51: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/51.jpg)
Update• Mutate the multi value• Add the value• Set the value on the person• Save the Address Book
Step Two
21Tuesday, February 16, 2010
![Page 52: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/52.jpg)
Update• Mutate the multi value• Add the value• Set the value on the person• Save the Address Book
ABMultiValueRef urls = ABRecordCopyValue(person, kABPersonURLProperty);
ABMutableMultiValueRef urlCopy = ABMultiValueCreateMutableCopy(urls);ABMultiValueAddValueAndLabel(urlCopy, "the url", "social", NULL);ABRecordSetValue(person, urlCopy, kABPersonURLProperty);
ABAddressBookSave(ab, &err);
Step Two
21Tuesday, February 16, 2010
![Page 53: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/53.jpg)
Display• Sort• Get the name• Display
Step Three
22Tuesday, February 16, 2010
![Page 54: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/54.jpg)
Sorting• We’ll do it for you• ABPersonGetSortOrdering• ABPersonComparePeopleByName
23Tuesday, February 16, 2010
![Page 55: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/55.jpg)
Sorting• We’ll do it for you• ABPersonGetSortOrdering• ABPersonComparePeopleByName
CFMutableArrayRef people = // obtain an array of peopleCFRange fullRange = CFRangeMake(0, CFArrayGetCount(people));
ABPersonSortOrdering sortOrdering = ABPersonGetSortOrdering();
CFArraySortValues(people, fullRange, ABPersonComparePeopleByName, (void*)sortOrdering);
23Tuesday, February 16, 2010
![Page 56: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/56.jpg)
Sorting• We’ll do it for you• ABPersonGetSortOrdering• ABPersonComparePeopleByName
CFMutableArrayRef people = // obtain an array of peopleCFRange fullRange = CFRangeMake(0, CFArrayGetCount(people));
ABPersonSortOrdering sortOrdering = ABPersonGetSortOrdering();
CFArraySortValues(people, fullRange, ABPersonComparePeopleByName, (void*)sortOrdering);
// Objective-C alternative[people sortUsingFunction:ABPersonComparePeopleByName context:(void*)sortOrdering];
23Tuesday, February 16, 2010
![Page 57: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/57.jpg)
Getting the Name• ABRecordCopyCompositeName
24Tuesday, February 16, 2010
![Page 58: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/58.jpg)
Getting the Name• ABRecordCopyCompositeName
ABRecordRef person = // get a personCFStringRef name = ABRecordCopyCompositeName(person);
// do something clever with that person’s name
24Tuesday, February 16, 2010
![Page 59: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/59.jpg)
Getting the Name• ABRecordCopyCompositeName
ABRecordRef person = // get a personCFStringRef name = ABRecordCopyCompositeName(person);
// do something clever with that person’s name
ABRecordRef person = // get a personNSString *name = (NSString*)ABRecordCopyCompositeName(person);
// do something clever with that person’s name
24Tuesday, February 16, 2010
![Page 60: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/60.jpg)
DemoBringing the people to the phone
25Tuesday, February 16, 2010
![Page 61: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/61.jpg)
What We Just Saw• Searching for people by name• Using multi values• Sorting and Displaying people
26Tuesday, February 16, 2010
![Page 62: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/62.jpg)
Showing Detailed Information
27Tuesday, February 16, 2010
![Page 63: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/63.jpg)
Person View Controller• ABPersonViewController
■ displayedPerson■ displayedProperties■ allowsEditing
28Tuesday, February 16, 2010
![Page 64: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/64.jpg)
Adding Contacts to Address Book
29Tuesday, February 16, 2010
![Page 65: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/65.jpg)
Unknown Person View Controller• ABUnknownPersonViewController
■ displayedPerson■ allowsAddingToAddressBook■ delegate
30Tuesday, February 16, 2010
![Page 66: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/66.jpg)
Unknown Person View Controller• ABUnknownPersonViewController
■ displayedPerson■ allowsAddingToAddressBook■ delegate
- (void)unknownPersonViewController:(ABUnknownPersonViewController *)unknownCardViewController didResolveToPerson:(ABRecordRef)person {
// do something
}
30Tuesday, February 16, 2010
![Page 67: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/67.jpg)
DemoShowing the people
31Tuesday, February 16, 2010
![Page 68: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/68.jpg)
What Did We Just See?• Display contacts with ABPersonViewController• Add to Address Book with ABUnknownPersonViewController
32Tuesday, February 16, 2010
![Page 69: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/69.jpg)
What If It Takes Too Long?• Doing things in the background
■ NSThread■ pthread
33Tuesday, February 16, 2010
![Page 70: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/70.jpg)
Threading Model• Each thread needs its own ABAddressBookRef• What you can pass between threads:
■ Values■ ABRecordID
34Tuesday, February 16, 2010
![Page 71: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/71.jpg)
Using the PeopleAdding people to an existing application
35Tuesday, February 16, 2010
![Page 72: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/72.jpg)
Pick an email address and send an email• Create an email button• Pick a person• Build an email URL and open it
36Tuesday, February 16, 2010
![Page 73: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/73.jpg)
Picking People• ABPeoplePickerNavigationController
37Tuesday, February 16, 2010
![Page 74: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/74.jpg)
Picking People• ABPeoplePickerNavigationController
37Tuesday, February 16, 2010
![Page 75: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/75.jpg)
Picking People• ABPeoplePickerNavigationController
37Tuesday, February 16, 2010
![Page 76: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/76.jpg)
ABPeoplePickerNavigationController• Present the Navigation Controller• ABPeoplePickerNavigationControllerDelegate
■ Cancellation■ Selection of a person■ Selection of a value
38Tuesday, February 16, 2010
![Page 77: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/77.jpg)
DemoBecause my friends like to receive emails
39Tuesday, February 16, 2010
![Page 78: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/78.jpg)
What We Just Saw• Present ABPeoplePickerNavigationController modally• Delegate callbacks
40Tuesday, February 16, 2010
![Page 79: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/79.jpg)
People Storage• Get the record identifier• Serialize and deserialize it• Look it up in Address Book
41Tuesday, February 16, 2010
![Page 80: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/80.jpg)
People Storage• Get the record identifier• Serialize and deserialize it• Look it up in Address Book
ABRecordID personID = ABRecordGetRecordID(person);NSNumber *personIDAsNumber = [NSNumber numberWithInt:personID];
// serialize the NSNumber
41Tuesday, February 16, 2010
![Page 81: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/81.jpg)
People Storage• Get the record identifier• Serialize and deserialize it• Look it up in Address Book
ABRecordID personID = ABRecordGetRecordID(person);NSNumber *personIDAsNumber = [NSNumber numberWithInt:personID];
// serialize the NSNumber
NSNumber *personIDAsNumber = // Deserialize the NSNumberABRecordID personID = [personIDAsNumber intValue];
ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab, personID);
41Tuesday, February 16, 2010
![Page 82: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/82.jpg)
What if the Database Changed?• Check before displaying• Store extra information
42Tuesday, February 16, 2010
![Page 83: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/83.jpg)
What if the Database Changed?• Check before displaying• Store extra information
ABRecordID recordID = // get the record
ABRecordRef person = ABAddressBookGetPersonWithRecordID(ab, personID);
if (person != NULL) { // use the person} else { // fallback to other data}
42Tuesday, February 16, 2010
![Page 84: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/84.jpg)
Notifications• Register callback
■ ABAddressBookRegisterExternalChangeCallback■ C callback
• And then what?■ Revert to get the changes■ Update the user interface
43Tuesday, February 16, 2010
![Page 85: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/85.jpg)
Notifications• Register callback
■ ABAddressBookRegisterExternalChangeCallback■ C callback
• And then what?■ Revert to get the changes■ Update the user interface
// Recipe Detail View ControllerABAddressBookRegisterExternalChangeCallback(ab, abChanged, self);
43Tuesday, February 16, 2010
![Page 86: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/86.jpg)
Notifications• Register callback
■ ABAddressBookRegisterExternalChangeCallback■ C callback
• And then what?■ Revert to get the changes■ Update the user interface
// Recipe Detail View ControllerABAddressBookRegisterExternalChangeCallback(ab, abChanged, self);
void abChanged(ABAddressBookRef ab, CFDictionaryRef info, void *context) { ABAddressBookRevert(ab); [(RecipeDetailViewController*)context reloadData];}
43Tuesday, February 16, 2010
![Page 87: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/87.jpg)
More on Change Callbacks• Revert or ignore the changes• Threading and change callbacks
44Tuesday, February 16, 2010
![Page 88: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/88.jpg)
Summary• Low level C API for dealing with people• View controllers for presenting the people
45Tuesday, February 16, 2010
![Page 89: CS193P - Lecture 13 · CS193P - Lecture 13 iPhone Application Development Address Book - Putting People in Your App Tuesday, February 16, 2010 1](https://reader034.fdocuments.in/reader034/viewer/2022042323/5f0d16947e708231d4389efa/html5/thumbnails/89.jpg)
Questions?
46Tuesday, February 16, 2010