iPhone's entire addressbook data

I want to create my custom addressbook like iphone's addressbook in which i am going to change some fields according to my needs.

So i would like to copy the iphone's entire addressbook data into my sql db.Please provide me any links or references for this.

need to know the db operation to store the addressbook data

Thanks


you can load the address book entries in an NSMutable array by this procedure and then you can do whatever you want to in your application:

-(NSMutableArray*)loadContactsFromAddressBook{

NSMutableArray * contacts = [[NSMutableArray alloc] init];
ABAddressBookRef addressBook = ABAddressBookCreate( );
CFArrayRef allPeople = ABAddressBookCopyArrayOfAllPeople( addressBook );
CFIndex nPeople = ABAddressBookGetPersonCount( addressBook );

for ( int i = 0; i < nPeople; i++ )
{

    ABRecordRef ref = CFArrayGetValueAtIndex( allPeople, i );

    NSString    *fname = (NSString*)ABRecordCopyValue(ref, kABPersonFirstNameProperty);        
    NSString    *lname = (NSString*)ABRecordCopyValue(ref, kABPersonLastNameProperty); 

    NSString    *name;
    NSString* phoneNumber;

    if (lname) {
        name = [fname stringByAppendingFormat: @" %@", lname];
    } else {
        name = fname;
    }

    ABMultiValueRef   phoneNumbers = ABRecordCopyValue(ref, kABPersonPhoneProperty);
    int count = ABMultiValueGetCount(phoneNumbers);

    if (count > 0 && name) {

        phoneNumber = (NSString*)ABMultiValueCopyValueAtIndex(phoneNumbers, 0);

        [contacts addObject:[NSMutableDictionary dictionaryWithObjectsAndKeys:name, @"member_name",
                             phoneNumber, @"phone",
                             @"NO", @"invited",
                             nil] ] ;
    }

    NSSortDescriptor *aSortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"member_name" ascending:YES];
    [contacts sortUsingDescriptors:[NSArray arrayWithObject:aSortDescriptor]];
}
return [contacts autorelease];
}

you'll need to add AddressBook.framework and AddressBookUI.framework frameworks to your project, and import AddressBook/AddressBook.h file in the class you use this method.

Hope this helps.


Instead of copying the entire address book into a DB (sync is always a pain), why not store your extended data in a DB with your DB data reference and address book entities? If you do that, you can reference an ABRecordRef id in your database.

链接地址: http://www.djcxy.com/p/51792.html

上一篇: 在iOS7中接收地址簿数据xCode(iOS 6正在运行)

下一篇: iPhone的全部地址簿数据