0

I am working with an addressbook application. In this, I have created methods that can add contacts to addressbook and update contact in local address book with the record of the person.

But the problem I am facing is that on a button click, I want to open the local address book of the person selected. How can I do that?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Rani
  • 3,333
  • 13
  • 48
  • 89
  • have you check http://stackoverflow.com/questions/7247579/how-to-programmatically-get-address-placeholder-text-from-iphone-addressbook – Nitin Gohel Dec 05 '12 at 05:35
  • what you want exactly?? you want to get contact and email and name of person from oue device?? – Paras Joshi Dec 05 '12 at 05:37
  • Check this: http://stackoverflow.com/questions/3732431/how-can-i-programmatically-launch-contacts-app-on-the-iphone – Bijoy Thangaraj Dec 05 '12 at 05:49
  • hey Rani,,,have you try this link...http://developer.apple.com/library/ios/#documentation/AddressBook/Reference/ABAddressBookRef_iPhoneOS/Reference/reference.html – NiravPatel Dec 05 '12 at 06:28

1 Answers1

0
contactList=[[NSMutableArray alloc] init];
ABAddressBookRef m_addressbook = ABAddressBookCreate();

if (!m_addressbook) 
{
    NSLog(@"opening address book");
}

CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople(m_addressbook);
CFIndex nPeople = ABAddressBookGetPersonCount(m_addressbook);

for (int i=0;i < nPeople;i++)
{
    NSMutableDictionary *dOfPerson=[NSMutableDictionary dictionary];
    ABRecordRef ref = CFArrayGetValueAtIndex(allPeople,i);

    //For username and surname
    ABMultiValueRef phones =(NSString*)ABRecordCopyValue(ref, kABPersonPhoneProperty);
    CFStringRef firstName, lastName;
    firstName = ABRecordCopyValue(ref, kABPersonFirstNameProperty);
    lastName  = ABRecordCopyValue(ref, kABPersonLastNameProperty);
   [dOfPerson setObject:[NSString stringWithFormat:@"%@ %@", firstName, lastName] forKey:@"name"];

    //For Email ids
    //ABMutableMultiValueRef eMail  = ABRecordCopyValue(ref, kABPersonEmailProperty);
    //if(ABMultiValueGetCount(eMail)> 0) {
    //[dOfPerson setObject:(NSString *)ABMultiValueCopyValueAtIndex(eMail, 0) forKey:@"email"];
   //}

    //For Phone number
    NSString* mobileLabel;
    for(CFIndex i = 0; i <ABMultiValueGetCount(phones); i++)
    {
        mobileLabel = (NSString*)ABMultiValueCopyLabelAtIndex(phones, i);
        if([mobileLabel isEqualToString:(NSString *)kABPersonPhoneMobileLabel])
        {
            [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
        }
        else if ([mobileLabel isEqualToString:(NSString*)kABPersonPhoneIPhoneLabel])
        {
            [dOfPerson setObject:(NSString*)ABMultiValueCopyValueAtIndex(phones, i) forKey:@"Phone"];
            break ;
        }
     }
     [contactList addObject:dOfPerson];
}  
Vaibhav Sharma
  • 1,123
  • 10
  • 22