On a recent troubleshooting attempt, I lost all the contacts in my Android phone. It had also received a recent update which took away the option to import contacts from another phone via bluetooth.
I still had some contacts in the old iPhone, but now that mass transfer via bluetooth is gone, it was a question of manually sending each contact in vCard format to the Android phone. That means I should probably find a less dreadful way to get the contacts back.
Here is one way to extract contacts en-masse from iPhone into popular vCard format. The contact and address details in iOS are stored by AddressBook application in a file named ‘AddressBook.sqlitedb
’ which is an sqlite database. The idea is to open this database using sqlite, extract the details from a couple of tables and convert the entries into vCard format.
Disclaimer: the iPhone is an old 3GS running iOS 6 and it is jailbroken. If you attempt this, your mileage would vary. Required tools/softwares are usbmuxd
(especially libusbmuxd-utils
) and sqlite
, with the prerequisite that openssh
server is running on the jailbroken iPhone.
- Connect iPhone via USB cable to the Linux machine. Run
iproxy 2222 22
to connect to the openssh server running on the jailbroken phone.iproxy
comes withlibusbmuxd-utils
package. - Copy the addressbook sqlite database from phone:
scp -P 2222 mobile@localhost:/var/mobile/Library/AddressBook/AddressBook.sqlitedb .
Instead of steps 1 and 2 above, it might be possible to copy this file using Nautilus (gvfs-afc
) or Dolphin (kio_afc
) file manager, although I’m not sure if the file is accessible. - Extract the contact and address details from the sqlite db (based on this forum post):
sqlite3 -cmd ".out contacts.txt" AddressBook.sqlitedb "select ABPerson.prefix, ABPerson.first,ABPerson.last,ABPerson.organization, c.value as MobilePhone, h.val ue as HomePhone, he.value as HomeEmail, w.value as WorkPhone, we.value as WorkEmail,ABPerson.note from ABPerson left outer join ABMultiValue c on c.record_id = ABPerson.ROWID and c.label = 1 and c.property= 3 left outer join ABMultiValue h on h.record_id = ABPerson.ROWID and h.label = 2 and h.property = 3 left outer join ABMultiValue he on he.record_id = ABPerson.ROWID and he.label = 2 and he.property = 4 left outer join ABMultiValue w on w.record_id = ABPerson.ROWID and w.label = 4 and w.property = 3 left outer join ABMultiValue we on we.record_id = ABPerson.ROWID and we.label = 4 and we.property = 4;"
- Convert the extracted contact details to vCard format:
cat contacts.txt | awk -F\| '{print "BEGIN:VCARD\nVERSION:3.0\nN:"$3";"$2";;;\nFN:"$2" "$3"\nORG:"$4"\nEMAIL;type=INTERNET;type=WORK;type=pref:" $9"\nTEL;type=CELL;type=pref:"$5"\nTEL;TYPE=HOME:"$6"\nTEL;TYPE=WORK:"$8"\nNOTE:"$9"\nEND:VCARD\n"}' > Contacts.vcf
- Remove the empty content lines if some contacts do not have all the different fields:
sed -i '/.*:$/d' Contacts.vcf
Now simply transfer the Contact.vcf
file containing all the contact details to Android phone’s storage and import contacts from there.
7 responses to “Convert iPhone contacts to vCard”
A note: if you have iCloud connected (and uploaded all your contact list to Apple, urgh), then you could just export everything to vCard format through https://www.icloud.com.
Pretty much similar to what Android has through https://www.google.com/contacts/.
Indeed, it is precisely that (urgh) prevents me from syncing to iCloud 🙂
[…] Convert iPhone contacts to vCard […]
Why on earth you don’t store your contacts in the Google contacts? To write such hacker’s posts? 🙂
Alex, it is exactly the same reason as why I don’t store contacts in iCloud; may be google contacts is even worse. It merges all the email, google plus and random contacts I have with the phone contacts, and I *don’t* want to share any of it with Google.
Plus, partly because of the reason you cite 😉
You are awesome! 🙂
I searched for a way to get my iPhone 5s (iOS 8) contacts onto my android (7.1) phone and into my nextcloud. With the app “iFile” I started a webserver to transfer the addressbook (sqlitedb) to my PC and with your help I was able to create the VCF, I desperately needed.
You’re welcome!
I’m glad it was helpful and useful not just to me, but to another person as well.