Anju
Anju

Reputation: 524

Fetch all email-id of contact list of iphone in to the iphone app

I need to fetch all email id's of contacts which is present in contact list of iPhone. and then all email id to show in picker View in app. please give me ideas to solve this problem. Thanks to all,

Upvotes: 0

Views: 542

Answers (1)

Vignesh
Vignesh

Reputation: 10251

check this out,

    ABAddressBookRef _addressBookRef = ABAddressBookCreate();
    NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);

   NSMutableDictionary  *contactsInformation = [[NSMutableDictionary alloc] initWithCapacity:[allPeople count]];

    for (id record in allPeople) 
    {
        NSMutableDictionary *propertyList = [[NSMutableDictionary alloc] init];


        CFTypeRef emailProp = ABRecordCopyValue((ABRecordRef)record, kABPersonEmailProperty);
        NSString *email = [((NSArray *)ABMultiValueCopyArrayOfAllValues(emailProp)) objectAtIndex:0 ];
        if (!email) {
            email = @"";  
        }

        [propertyList setObject:email forKey:@"Email"];

        [contactsInformation setObject:propertyList forKey:[NSNumber numberWithInt:ABRecordGetRecordID((ABRecordRef)record)]];

        [propertyList release];
    }
    CFRelease(_addressBookRef);
    [allPeople release];
    allPeople = nil;

Upvotes: 3

Related Questions