开发者

Extract entire addressbook name & number from ABperson objective c iphone

开发者 https://www.devze.com 2023-01-07 06:52 出处:网络
I need to know how to extract everyname & number from the address book in xcode fo开发者_JS百科r the iphone. I need to have the name and number in the following format:

I need to know how to extract everyname & number from the address book in xcode fo开发者_JS百科r the iphone. I need to have the name and number in the following format:

John Doe:000000000000000 Jane Doe:000000000000000


Are you searching for all phone numbers of all people in the address book? Look at ABAddressBookCopyArrayOfAllPeople.

You could use it like this: (untested coded in browser)

    ABAddressBookRef _addressBookRef = ABAddressBookCreate ();
    NSArray* allPeople = (NSArray *)ABAddressBookCopyArrayOfAllPeople(_addressBookRef);
    NSMutableArray* _allItems = [[NSMutableArray alloc] initWithCapacity:[allPeople count]]; // capacity is only a rough guess, but better than nothing
    for (id record in allPeople) {
        CFTypeRef phoneProperty = ABRecordCopyValue((ABRecordRef)record, kABPersonPhoneProperty);
        NSArray *phones = (NSArray *)ABMultiValueCopyArrayOfAllValues(phoneProperty);
        CFRelease(phoneProperty);
        for (NSString *phone in phones) {
            NSString* compositeName = (NSString *)ABRecordCopyCompositeName((ABRecordRef)record);
            NSString* field = [NSString stringWithFormat@"%@:%@",compositeName,phone];
            [compositeName release];
            [_allItems addObject:field];
        }
        [phoness release];
    }
    CFRelease(_addressBookRef);
    [allPeople release];
    allPeople = nil;
0

精彩评论

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