iCloud, The forced cloud transition

I own an iPhone 4 from the first day it was released till now (iPhone 6 was just announced today). I know myself as an iPhone expert but due to some issues with my iPhone 4 mainboard, I had not updated it to iOS 7.x till today (Mostly laziness and having the comfort zone in iOS 6 terminal). Anyhow, I decided to update it before iOS 8 is released, so I did. This would be the last update on my iPhone 4 before I get the new iPhone 6.

One more thing I should mention is that I had all my contacts and texts and everything since my iPhone 2G (September 2007). So imagine how big my text database was, So I decided to start fresh and do not restore my backup and just sync my contacts and notes and all the required info I needed but not the history.

Anyways, everything went great and I updated my phone to 7.1.2, Jailbreak it with Pangu, and installed my apps. seemed like it’s complete.

Today I noticed I do not have most of my recently added contacts in my contact list, nor in my Mac’s contacts (around 300 contacts were missing). So I digged in and realized it only synced the contacts I had on iCloud and apparently the phone numbers that I saved when I had a text message or call from them was saved on my local contact database and had not been uploaded to iCloud.

So I decided to dig into this and restore every contact I had to the clouds and so to my phone.

I launched the good old iPhone Backup Extractor and extracted all the iOS files from my backup.

iPhone backup Extractor

iPhone backup Extractor

Then went to iOS Files/Library/AddressBook/ and there was, my lovely AddressBook.sqlitedb.

iOS addressbook tables are a mess in some ways unless you know what you’re doing. I cut it short and write only the commands needed to extract your contacts to a readable format.

so I launched up sqlite3 in Terminal:

Screen Shot 2014-09-09 at 11.55.18 PM

sqlite> .mode csv

sqlite> .output contacts.csv

sqlite> select ROWID, first, last, organization, identifier, value, record_id from ABPerson p join ABMultiValue mv on (ROWID=record_id);

and in addition you can add any other fields that you need to extract those too. Here is the make table sql commands from the original file, you can see all the fields.

 .tables ABGroup ABPersonMultiValueDeletes ABGroupChanges ABPersonSearchKey ABGroupMembers ABPhoneLastFour ABMultiValue ABRecent ABMultiValueEntry ABStore ABMultiValueEntryKey FirstSortSectionCount ABMultiValueLabel LastSortSectionCount ABPerson _SqliteDatabaseProperties ABPersonChanges

.schema ABPerson CREATE TABLE ABPerson (ROWID INTEGER PRIMARY KEY AUTOINCREMENT, First TEXT, Last TEXT, Middle TEXT, FirstPhonetic TEXT, MiddlePhonetic TEXT, LastPhonetic TEXT, Organization TEXT, Department TEXT, Note TEXT, Kind INTEGER, Birthday TEXT, JobTitle TEXT, Nickname TEXT, Prefix TEXT, Suffix TEXT, FirstSort TEXT, LastSort TEXT, CreationDate INTEGER, ModificationDate INTEGER, CompositeNameFallback TEXT, ExternalIdentifier TEXT, StoreID INTEGER, DisplayName TEXT, ExternalRepresentation BLOB, FirstSortSection TEXT, LastSortSection TEXT, FirstSortLanguageIndex INTEGER DEFAULT 2147483647, LastSortLanguageIndex INTEGER DEFAULT 2147483647);

.schema ABMultiValue CREATE TABLE ABMultiValue (UID INTEGER PRIMARY KEY, record_id INTEGER, property INTEGER, identifier INTEGER, label INTEGER, value TEXT);

In the end, you would have a comma seperated file that has these columns:

First Name, Last Name, Company, (Home, Work, …. Label as integer), Phone Number, Record_id(Probably not needed)

now to import them into the contact list the easiest way (sometimes it’s easier to write a python script to do so, but in this case this one is pretty much easier for 4 A.M 🙂 ) is to import it into your Mac’s Contacts application, define each field, import all (Keep Both) and Update the old contacts to have all the numbers of each contact and not to replace them by eachother (Home, Work, Mobile and … ).

Screen Shot 2014-09-10 at 12.05.05 AM

And in the end Merge all the duplicates, this would merge all the phone numbers of Mr. A to one contact entity. there might be some duplicate numbers in one entity of contact but it’s nothing that bothers you in the end.

Screen Shot 2014-09-10 at 12.06.06 AM

And now everything restored and uploaded to the cloud, not sure if it’s a good thing but I have everything on my phone before iOS 8 is released so it’s a win for me. 🙂


UPDATE: Apparently this issue is something kinda general, There are lots of Notes missing too.


%d bloggers like this: