Search code examples
iphoneios9icloudcontacts

CNContact(s) created locally are not synced to iCloud account


Recently some of our users were complaining about contacts not syncing to their iCloud account. It was working in iOS 8 and mysteriously stopped in one of the updates in iOS 9. With iOS 10 around the corner I thought it might be linked to deprecation of AddressBook.framework to Contacts.framework. However, even moving to new Contacts.framework it didn't fix the problem.

There are no error logs on console of the device and neither of the frameworks generate any errors when contacts are being created/updated on the device.

Contacts are visible and available on the device just not syncing to iCloud and other devices attached to the iCloud account.


Solution

  • After a lot of debugging what I was able to isolate the issue to imageData property. Contacts which had imageData populated were not synced and the few which had no images were synced. This lead me to look at the code for imageData. Turns out I had been using UIImagePNGRepresentation to convert UIImage to NSData for imageData. Moving to UIImageJPEGRepresentation fixed the issue. The day was saved and iCloud accounts are synced.

    Thank you Apple for not documenting this change. (it might be the image size even that is not documented)