In this how to series, I have come up with yet another code snippet, which allows you to use iPhone’s contact data into your own application. The code is:
-(void)retrieveContactList
{
ABAddressBookRef myAddressBook = ABAddressBookCreate();
NSArray *allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(myAddressBook);
contactList = [[NSMutableArray alloc]initWithCapacity:[allPeople count]];
for (id record in allPeople) {
CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
//NSLog(@”phones array: %@”, phones);
CFRelease(phoneProperty);
NSString* contactName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
NSMutableDictionary *newRecord = [[NSMutableDictionary alloc] init];
[newRecord setObject:contactName forKey:@"name"];
//[contactName release];
NSMutableString *newPhone = [[NSMutableString alloc] init];
for (NSString *phone in phones) {
//NSString *fieldData = [NSString stringWithFormat:@"%@: %@", contactName, phone];
if(![newPhone isEqualToString:@""])
[newPhone appendString:@", "];
[newPhone appendString:phone];
}
[newRecord setObject:newPhone forKey:@"phone"];
[newPhone release];
[phones release];
[contactList addObject:newRecord];
//[newPhone release];
}
CFRelease(myAddressBook);
// NSLog(@”Final data: %@”, contactList);
}
Enjoy!
How to use iPhone contacts in your own application
Posted:
Sunday, February 13, 2011 |
Posted by
Dipak Mishra
|
Share
Tweet
Subscribe to:
Post Comments (Atom)
Blog Archive
-
►
2008
(15)
-
►
May
(9)
- Competition for MacBook Air
- If you are willing to work
- Some Libraries in JavaScript
- Utility function to get current X and Y position o...
- Utility Class to change local time in GMT and GMT ...
- Interesting Javascript functions
- How to make an image draggable (Google Map Type)
- Life is interesting
- Speed optimization in ASP .Net web applications
-
►
May
(9)
Popular Posts
-
In iPad, we have a new control called UIPopover. This control shows up as an overlay in the screen with a UIViewController or UIView in it. ...
-
Today I came across a unique problem. I was working on a Drupal website for one of my clients and there I was required to create a page to s...
-
/*-------This works for IE and non IE as well----------------*/ var oScript = document.createElement("script"); oScript.src = fileName.js; d...
-
A lot of time I came across a common problem of showing background image in navigation bar of iPhone application. For very first time, I use...
-
While researching about image manipulation for my next project, I came across an interesting piece of code, using which, we can merge two im...
Topics
asp .net
(3)
c#
(2)
Drupal
(3)
How To
(6)
iPhone
(10)
java
(1)
javascript
(8)
laptop
(1)
Life Style
(2)
linux
(1)
logout
(1)
New Technologies
(1)
optimization
(1)
PHP
(2)
planning
(1)
Recession
(1)
resource
(1)
reviews
(1)
secure download
(1)
SEO
(1)
servlet
(1)
skills
(1)
success
(1)
tips
(3)
tutorial
(2)
UIWebView
(1)
Utilities
(4)
web development
(2)
Web technology
(1)
website
(1)
0 comments:
Post a Comment
Tweet