开发者

Issue regarding retrieving all email id's from address book in iphone

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


There are a couple of online tutorials here that should help:

http://iphone.zcentric.com/2008/09/19/access-the-address-book/

https://developer.apple.com/iphone/library/documentation/ContactData/Conceptual/AddressBookProgrammingGuideforiPhone/100-Introduction/Introduction.html


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜