objective c - Backup complete iPhone AdressBook programmatically -


i need backup contacts records (numbers, names, image, ...) programmatically. read adressbook.framework, there easy way make backup contacts?

1.one way of doing create vcard string contacts. this:

abaddressbookref addressbook = abaddressbookcreate(); cfarrayref peopleforbackup  = abaddressbookcopyarrayofallpeople(addressbook); cfdataref vcards = (cfdataref)abpersoncreatevcardrepresentationwithpeople(peopleforbackup); vcardstring = [[nsstring alloc] initwithdata:(nsdata *)vcards encoding:nsutf8stringencoding]; 

and write string file backup.

2.delete current contacts address book:

abaddressbookref addressbook = abaddressbookcreate(); cfarrayref people = abaddressbookcopyarrayofallpeople(addressbook); int arraycount = cfarraygetcount(people); abrecordref abrecord;  (int = 0; < arraycount; i++) {     abrecord = cfarraygetvalueatindex(people, i);     abaddressbookremoverecord(addressbook,abrecord, null); } cfrelease(people); 

3.to restore backup read vcard file string , itterate through person-records in vcard , add them records addressbook, save it.

abaddressbookref addressbook = abaddressbookcreate(); nsdata *stringdata = [nsdata datawithcontentsoffile:contactfilepath]; nsstring *vcardfromfile = [[nsstring alloc] initwithdata:stringdata encoding:nsutf8stringencoding];  cfdataref vcarddata = (cfdataref)[vcardfromfile datausingencoding:nsutf8stringencoding];  abrecordref defaultsource = abaddressbookcopydefaultsource(addressbook); cfarrayref vcardpeople = abpersoncreatepeopleinsourcewithvcardrepresentation(defaultsource, vcarddata);  (cfindex index = 0; index < cfarraygetcount(vcardpeople); index++) {     abrecordref person = cfarraygetvalueatindex(vcardpeople, index);     abaddressbookaddrecord(addressbook, person, null);     cfrelease(person); }  cfrelease(vcardpeople); cfrelease(defaultsource); bool success = abaddressbooksave(addressbook, null); 

a problem approach dont know of way maintain linking of contacts (exchange, facebook...).


Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -