<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>de &#187; addressbook</title>
	<atom:link href="http://duivesteyn.net/tag/addressbook/feed/" rel="self" type="application/rss+xml" />
	<link>http://duivesteyn.net</link>
	<description></description>
	<lastBuildDate>Tue, 20 Apr 2010 22:00:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>iPhone OS SDK &#8211; Contact Address Property</title>
		<link>http://duivesteyn.net/2010/03/17/iphone-sdk-contact-address-property/</link>
		<comments>http://duivesteyn.net/2010/03/17/iphone-sdk-contact-address-property/#comments</comments>
		<pubDate>Wed, 17 Mar 2010 10:11:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone SDK Tips]]></category>
		<category><![CDATA[addressbook]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://duivesteyn.net/2010/03/17/iphone-sdk-contact-address-property/</guid>
		<description><![CDATA[Today something quick. I&#8217;m working with addressbook information and I am extracting data from a contact, I already know I want in the addressbook (addressbookID=45 lets say). How do I get their address? And their Name, Company, Phone Number and Email! Use the following. NSLog(@&#8221;Looking Up Contact Now&#8221;); ABAddressBookRef ab = ABAddressBookCreate(); ABRecordRef person = [...]]]></description>
			<content:encoded><![CDATA[<p><span style="color: #000000;"><span style="font-size: small;">Today something quick. I&#8217;m working with addressbook information and I am extracting data from a contact, I already know I want in the addressbook (addressbookID=45 lets say).<br />
 How do I get their address?</span></span><span style="font-size: small;"> </span><span style="color: #000000;"><span style="font-size: small;">And their Name, Company, Phone Number and Email!</span></span></p>
<p><span style="color: #000000;"><span style="font-size: small;"><br />
 Use the following.</span></span></p>
<p><span style="font-size: small;"> </span> <span style="color: #2e0d6e;">NSLog</span><span style="color: #000000;">(</span><span style="color: #c41a16;">@&#8221;Looking Up Contact Now&#8221;</span><span style="color: #000000;">);<br />
 </span><span style="color: #5c2699;">ABAddressBookRef</span> <span style="color: #000000;">ab = </span><span style="color: #2e0d6e;">ABAddressBookCreate</span><span style="color: #000000;">();<br />
 </span><span style="color: #5c2699;">ABRecordRef</span> <span style="color: #000000;">person = </span><span style="color: #2e0d6e;">ABAddressBookGetPersonWithRecordID</span><span style="color: #000000;">(ab,item2.integerValue);</span></p>
<p><span style="color: #2e0d6e;">NSLog</span><span style="color: #000000;">(</span><span style="color: #c41a16;">@&#8221;person: %d&#8221;</span><span style="color: #000000;">,person);<br />
 </span><span style="color: #aa0d91;">if</span> <span style="color: #000000;">(person != </span><span style="color: #aa0d91;">nil</span><span style="color: #000000;">) {</p>
<p> </span><span style="color: #007400;">//Name </span><br />
 <span style="color: #3f6e74;">myName</span> <span style="color: #000000;">= (</span><span style="color: #5c2699;">NSString</span> <span style="color: #000000;">*)</span><span style="color: #2e0d6e;">ABRecordCopyCompositeName</span><span style="color: #000000;">(person);</span></p>
<p><span style="color: #007400;">//Company</span><br />
 <span style="color: #3f6e74;">myCompany</span> <span style="color: #000000;">= (</span><span style="color: #5c2699;">NSString</span> <span style="color: #000000;">*)</span><span style="color: #2e0d6e;">ABRecordCopyValue</span><span style="color: #000000;">(person, </span><span style="color: #5c2699;">kABPersonOrganizationProperty</span><span style="color: #000000;">);</span></p>
<p><span style="color: #007400;">//Email Address (this one is tricky)</span><br />
 <span style="color: #5c2699;">ABMutableMultiValueRef</span> <span style="color: #000000;">emailMulti = </span><span style="color: #2e0d6e;">ABRecordCopyValue</span><span style="color: #000000;">(person, </span><span style="color: #5c2699;">kABPersonEmailProperty</span><span style="color: #000000;">);<br />
 </span><span style="color: #5c2699;">NSMutableArray</span> <span style="color: #000000;">*emails = [[</span><span style="color: #5c2699;">NSMutableArray</span> <span style="color: #2e0d6e;">alloc</span><span style="color: #000000;">] </span><span style="color: #2e0d6e;">init</span><span style="color: #000000;">];<br />
 </span><span style="color: #aa0d91;">for</span> <span style="color: #000000;">(</span><span style="color: #aa0d91;">int</span> <span style="color: #000000;">i = </span><span style="color: #1c00cf;">0</span><span style="color: #000000;">; i &lt; </span><span style="color: #2e0d6e;">ABMultiValueGetCount</span><span style="color: #000000;">(emailMulti); i++) {<br />
 </span><span style="color: #5c2699;">NSString</span> <span style="color: #000000;">*anEmail = [(</span><span style="color: #5c2699;">NSString</span><span style="color: #000000;">*)</span><span style="color: #2e0d6e;">ABMultiValueCopyValueAtIndex</span><span style="color: #000000;">(emailMulti, i) </span><span style="color: #2e0d6e;">autorelease</span><span style="color: #000000;">];<br />
 [emails </span><span style="color: #2e0d6e;">addObject</span><span style="color: #000000;">:anEmail];<br />
 }</span></p>
<p><span style="color: #000000;"><br />
 </span><span style="color: #aa0d91;">if</span><span style="color: #000000;">([emails </span><span style="color: #2e0d6e;">count</span><span style="color: #000000;">] &gt; </span><span style="color: #1c00cf;">0</span><span style="color: #000000;">) </span><span style="color: #3f6e74;">myEmail</span> <span style="color: #000000;">= [emails </span><span style="color: #2e0d6e;">objectAtIndex</span><span style="color: #000000;">:</span><span style="color: #1c00cf;">0</span><span style="color: #000000;">];</span></p>
<p><span style="color: #007400;">//Phone Numbers</span><br />
 <span style="color: #5c2699;">ABMultiValueRef</span> <span style="color: #000000;">phoneNumberProperty = </span><span style="color: #2e0d6e;">ABRecordCopyValue</span><span style="color: #000000;">(person, </span><span style="color: #5c2699;">kABPersonPhoneProperty</span><span style="color: #000000;">);<br />
 </span><span style="color: #5c2699;">NSArray</span><span style="color: #000000;">* phoneNumbers = (</span><span style="color: #5c2699;">NSArray</span><span style="color: #000000;">*)</span><span style="color: #2e0d6e;">ABMultiValueCopyArrayOfAllValues</span><span style="color: #000000;">(phoneNumberProperty);<br />
 </span><span style="color: #2e0d6e;">CFRelease</span><span style="color: #000000;">(phoneNumberProperty);</p>
<p> </span><span style="color: #007400;">// Do whatever you want with the phone numbers</span><br />
 <span style="color: #2e0d6e;">NSLog</span><span style="color: #000000;">(</span><span style="color: #c41a16;">@&#8221;Phone numbers = %@&#8221;</span><span style="color: #000000;">, phoneNumbers);</span></p>
<p><span style="color: #007400;">//Location Address</span><br />
 <span style="color: #5c2699;">ABMutableMultiValueRef</span> <span style="color: #000000;">addressMulti = </span><span style="color: #2e0d6e;">ABRecordCopyValue</span><span style="color: #000000;">(person, </span><span style="color: #5c2699;">kABPersonAddressProperty</span><span style="color: #000000;">);<br />
 </span><span style="color: #5c2699;">NSMutableArray</span> <span style="color: #000000;">*address = [[</span><span style="color: #5c2699;">NSMutableArray</span> <span style="color: #2e0d6e;">alloc</span><span style="color: #000000;">] </span><span style="color: #2e0d6e;">init</span><span style="color: #000000;">];<br />
 </span><span style="color: #aa0d91;">int</span> <span style="color: #000000;">i;<br />
 </span><span style="color: #aa0d91;">for</span> <span style="color: #000000;">(i = </span><span style="color: #1c00cf;">0</span><span style="color: #000000;">; i &lt; </span><span style="color: #2e0d6e;">ABMultiValueGetCount</span><span style="color: #000000;">(addressMulti); i++) {<br />
 </span><span style="color: #5c2699;">NSString</span> <span style="color: #000000;">*city = [(</span><span style="color: #5c2699;">NSString</span><span style="color: #000000;">*)</span><span style="color: #2e0d6e;">ABMultiValueCopyValueAtIndex</span><span style="color: #000000;">(addressMulti, i) </span><span style="color: #2e0d6e;">autorelease</span><span style="color: #000000;">];<br />
 [address </span><span style="color: #2e0d6e;">addObject</span><span style="color: #000000;">:city];<br />
 }<br />
 </span><span style="color: #2e0d6e;">NSLog</span><span style="color: #000000;">(</span><span style="color: #c41a16;">@&#8221;addresses: %@&#8221;</span><span style="color: #000000;">,address);</span></p>
<p>} <span style="color: #aa0d91;">else</span> <span style="color: #000000;">{<br />
 </span><span style="color: #5c2699;">UIAlertView</span> <span style="color: #000000;">*baseAlert = [[</span><span style="color: #5c2699;">UIAlertView</span> <span style="color: #2e0d6e;">alloc</span><span style="color: #000000;">] </span><span style="color: #2e0d6e;">initWithTitle</span><span style="color: #000000;">:</span><span style="color: #c41a16;">@&#8221;Address Link&#8221;</span> <span style="color: #2e0d6e;">message</span><span style="color: #000000;">:</span><span style="color: #c41a16;">@&#8221;Sorry, no address book link available&#8221;</span> <span style="color: #2e0d6e;">delegate</span><span style="color: #000000;">:</span><span style="color: #aa0d91;">self</span> <span style="color: #2e0d6e;">cancelButtonTitle</span><span style="color: #000000;">:</span><span style="color: #aa0d91;">nil</span> <span style="color: #2e0d6e;">otherButtonTitles</span><span style="color: #000000;">:</span><span style="color: #c41a16;">@&#8221;OK&#8221;</span><span style="color: #000000;">, </span><span style="color: #aa0d91;">nil</span><span style="color: #000000;">];<br />
 [baseAlert </span><span style="color: #2e0d6e;">show</span><span style="color: #000000;">];<br />
 }<br />
 </span></p>
]]></content:encoded>
			<wfw:commentRss>http://duivesteyn.net/2010/03/17/iphone-sdk-contact-address-property/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhoneOS Addressbook Create New Client &amp; Get Data</title>
		<link>http://duivesteyn.net/2010/03/05/iphoneos-addressbook-create-new-client-get-data/</link>
		<comments>http://duivesteyn.net/2010/03/05/iphoneos-addressbook-create-new-client-get-data/#comments</comments>
		<pubDate>Fri, 05 Mar 2010 07:00:21 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone SDK Tips]]></category>
		<category><![CDATA[addressbook]]></category>
		<category><![CDATA[iphoneOS]]></category>

		<guid isPermaLink="false">http://duivesteyn.net/?p=497</guid>
		<description><![CDATA[I just finished a snippet of code for an upcoming 1 day iphonedev project which is very simple. The snippet needs to show the user an add address book contact box, let the user add the contact info and then Dismiss the add contact window to get on with the rest of the app, and [...]]]></description>
			<content:encoded><![CDATA[<p><br class="spacer_" /></p>
<p><img class="size-full wp-image-500 alignright" title="Screen shot 2010-03-04 at 08.47.06" src="http://duivesteyn.net/wp-content/uploads/2010/03/Screen-shot-2010-03-04-at-08.47.06.png" alt="" width="174" height="323" /></p>
<div id="_mcePaste">I just finished a snippet of code for an upcoming 1 day iphonedev project which is very simple. The snippet needs to show the user an add address book contact box, let the user add the contact info and then Dismiss the add contact window to get on with the rest of the app, and of course saving the data into memory.</div>
<div id="_mcePaste">The code is attached below, and be sure to be watching the NSLog.</div>
<div></div>
<p style="text-align: auto;"><span style="font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; font-size: small;"><span style="line-height: normal; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><span style="font-family: Georgia, 'Times New Roman', 'Bitstream Charter', Times, serif; font-size: small;"><span style="line-height: 19px; white-space: normal; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px;"><br />
</span></span></span></span></p>
<p style="text-align: center;"><span style="font-family: 'Lucida Grande', Verdana, Arial, 'Bitstream Vera Sans', sans-serif; line-height: normal; font-size: 12px; white-space: pre; -webkit-border-horizontal-spacing: 2px; -webkit-border-vertical-spacing: 2px;"><a href="http://duivesteyn.net/wp-content/uploads/2010/03/iphonesdk-snippetcode-newcontactviainterface.zip"><img class="alignnone size-full wp-image-498" title="icon" src="http://duivesteyn.net/wp-content/uploads/2010/03/icon.png" alt="" width="346" height="138" /></a></span></p>
<p><br class="spacer_" /></p>
<p><br class="spacer_" /></p>
]]></content:encoded>
			<wfw:commentRss>http://duivesteyn.net/2010/03/05/iphoneos-addressbook-create-new-client-get-data/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iPhone Development SDK &#8211; Working with the Address BookRight</title>
		<link>http://duivesteyn.net/2010/01/26/iphone-development-sdk-working-with-the-address-bookright/</link>
		<comments>http://duivesteyn.net/2010/01/26/iphone-development-sdk-working-with-the-address-bookright/#comments</comments>
		<pubDate>Tue, 26 Jan 2010 15:15:32 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[iPhone SDK Tips]]></category>
		<category><![CDATA[addressbook]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[iphone]]></category>

		<guid isPermaLink="false">http://duivesteyn.net/?p=105</guid>
		<description><![CDATA[Lately I&#8217;ve spent a bit of time learning the API for the iPhone Contacts Address Book. I&#8217;d like to share the process and help with some of the bits I found difficult. Including the Frameworks First the framework must be included in your Xcode project. Right Click on your project target and in the linked [...]]]></description>
			<content:encoded><![CDATA[<p>Lately I&#8217;ve spent a bit of time learning the API for the iPhone Contacts Address Book. I&#8217;d like to share the process and help with some of the bits I found difficult.</p>
<h2><span style="font-weight: normal;">Including the Frameworks</span></h2>
<p><img class="size-full wp-image-110 alignright" title="Screen shot 2010-01-26 at 15.43.57" src="http://duivesteyn.net/wp-content/uploads/2010/01/Screen-shot-2010-01-26-at-15.43.57.png" alt="" width="187" height="37" /></p>
<p>First the framework must be included in your Xcode project.</p>
<ol>
<li>Right Click on your project target and in the linked  libraries add AddressBook.framework, and AddressBookUI.framework</li>
<li>To add these, click the + button at the bottom of the properties box. In my case, the AddressbookUI.framework was not in the list. To add it I clicked &#8216;Add Other&#8217; and navigated to /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.2.1.sdk/System/Library/Frameworks. AddressBookUI.framework is in here. (if you don&#8217;t have folder 2.2.1, try any of the others).</li>
<li style="text-align: left;">If done correctly, your project should look like the one below.<span id="more-105"></span><br />
<img class="size-full wp-image-109 aligncenter" title="Screen shot 2010-01-26 at 15.44.02" src="http://duivesteyn.net/wp-content/uploads/2010/01/Screen-shot-2010-01-26-at-15.44.02.png" alt="" width="321" height="342" /></p>
<p>Don&#8217;t be alarmed if your frameworks are all red in your Xcode project, this is in fact how you want it.</li>
</ol>
<h2><span style="font-weight: normal;">Class Include</span></h2>
<p>To access the address book, in the working class header insert the following:</p>
<p><code>#import<br />
//AddressBook stuff<br />
#import<br />
#import</code></p>
<h2><span style="font-weight: normal;">Displaying Contact List</span></h2>
<p>The first thing I wanted to do was to draw the list of iPhone contacts, to allow one to be selected, and used as input.</p>
<p>On a click of an icon I execute the method: <strong>getContact</strong>. (See below). This calls the contact list to display, but it also requires the below <strong>peoplePickerNavigationControllerDidCancel</strong>,<strong>peoplePickerNavigationController</strong> and <strong>peoplePickerNavigationController.</strong></p>
<p>What the following code does is:</p>
<p style="text-align: left;">1. On click of getContact (figure 1), shows the contact list (figure 2), on selecting a contact from the list the contacts name (and company if available) is put into the textfields (figure 3). Simple right?</p>
<p style="text-align: center;"><a href="http://duivesteyn.net/wp-content/uploads/2010/01/AddressBook-View.png" rel="lightbox[105]"><img class="aligncenter size-large wp-image-127" title="iPhone-AddressBook-View" src="http://duivesteyn.net/wp-content/uploads/2010/01/AddressBook-View-1024x634.png" alt="" width="569" height="352" /></a></p>
<p><span style="line-height: 17px; font-size: small;"><span style="line-height: 19px;"><br />
</span></span></p>
<p><strong>getContact</strong></p>
<p><code>-(IBAction)getContact {<br />
// creating the picker<br />
ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];<br />
// place the delegate of the picker to the controll<br />
picker.peoplePickerDelegate = self;<br />
// showing the picker<br />
[self presentModalViewController:picker animated:YES];<br />
// releasing<br />
[picker release];<br />
}</code></p>
<p><strong>peoplePickerNavigationController</strong></p>
<p><code>- (BOOL)peoplePickerNavigationController: (ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person {<br />
NSString *contactName;<br />
NSString *contactCompany;<br />
NSString *contactFirst;<br />
NSString *contactLast;<br />
contactFirst = [(NSString *)ABRecordCopyValue(person, kABPersonFirstNameProperty) stringByAppendingString:@" "];<br />
contactLast =  (NSString *)ABRecordCopyValue(person, kABPersonLastNameProperty);<br />
contactName = [contactFirst stringByAppendingString:contactLast];<br />
contactCompany = (NSString *)ABRecordCopyValue(person, kABPersonOrganizationProperty);<br />
NSNumber *recordId = [NSNumber numberWithInteger: ABRecordGetRecordID(person)];<br />
NSLog(@"record id is %@",recordId);<br />
NSLog(@"Person Reference: %d", person);<br />
NSLog(@"Name: %@", contactName);<br />
NSLog(@"Company: %@", contactCompany);<br />
txtName.text = contactName;<br />
NSString *personStr = [NSString stringWithFormat:@"%@", recordId];<br />
txtPersonID.text = personStr;<br />
if (contactCompany != nil) txtCompanyName.text = contactCompany;<br />
// remove the controller<br />
[self dismissModalViewControllerAnimated:YES];<br />
return NO;<br />
}</code></p>
<p><strong>peoplePickerNavigationControllerDidCancel</strong></p>
<p><code>- (void)peoplePickerNavigationControllerDidCancel:(ABPeoplePickerNavigationController *)peoplePicker {<br />
// assigning control back to the main controller<br />
[self dismissModalViewControllerAnimated:YES];<br />
}</code></p>
<p><strong>peoplePickerNavigationController</strong></p>
<p><code>- (BOOL)peoplePickerNavigationController:(ABPeoplePickerNavigationController *)peoplePicker shouldContinueAfterSelectingPerson:(ABRecordRef)person property:(ABPropertyID)property identifier:(ABMultiValueIdentifier)identifier{<br />
return NO;<br />
}</code></p>
<p>Not only do I use the name of the contact, but I also access the vital PersonRecordID, which is more or less a unique identifier for each contact. For more information on this, search on the topic ABAddressBookGetPersonWithRecordID.</p>
<p>Could you follow that? Its pretty interesting to implement. There is of course the ability to access all the data in a contact, make edits, add new contacts, but I wanted to share what I have done myself.</p>
<p>For further information, google around! This is good too <a href="http://iphone.zcentric.com/?p=241" target="_blank">http://iphone.zcentric.com/?p=241</a>. I also found the <a id="project_summary_link" href="http://code.google.com/p/cookbooksamples/">iPhone Developer&#8217;s Cookbook Sample Code</a> quite useful. There are a couple good projects in Chapter 9 &#8211; People, Places, Things.</p>
<p><strong>References</strong></p>
<ul>
<li><a href="http://developer.apple.com/iphone/library/documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html" target="_blank">Apple Developer AddressBook Reference</a></li>
<p><a href="http://developer.apple.com/iphone/library/documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html" target="_blank"> </a></ul>
<p><a href="http://developer.apple.com/iphone/library/documentation/AddressBook/Reference/ABPersonRef_iPhoneOS/Reference/reference.html" target="_blank"></a></p>
]]></content:encoded>
			<wfw:commentRss>http://duivesteyn.net/2010/01/26/iphone-development-sdk-working-with-the-address-bookright/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
