I am newbie to Address book programming. I want to retrieve all email id's from address book.The issue is below code gets the all data for one record(one person). but When i add more than one contact in address book. it crushes without showing any exception.

Any suggestions? Thanks in advance.

   self.pastUrls = [[NSMutableArray alloc] init];


ABAddressBookRef addressBook = ABAddressBookCreate();

NSArray *addresses = (NSArray *) ABAddressBookCopyArrayOfAllPeople(addressBook);

// you could probably do some kind of enumeration but I'm doing old fashoined way
int i;
for(i = 0; i < [addresses count]; i++) {
    ABRecordRef record = [addresses objectAtIndex:i];


    ABMultiValueRef multiValue = ABRecordCopyValue(record, kABPersonEmailProperty);
    NSLog(@"%@",multiValue);

    int count = ABMultiValueGetCount(multiValue);
    NSLog(@"%d",count);
    int j;
    for(j = 0; j < count; j++) {
        NSString *label = (NSString *)ABAddressBookCopyLocalizedLabel(ABMultiValueCopyLabelAtIndex(multiValue, i));
        NSString *value = (NSString *)ABMultiValueCopyValueAtIndex(multiValue, i);

        //NSLog(@"Email for %@: %@", label, value);
        [pastUrls addObject:value];


    }
}

Regards, sathish

其他提示

Apple's Address Book Programming Guide for iOS includes a sample project that will get you started with general principles for accessing address book data, including email addresses.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top