Hello folks,
I stumbled upon a weird CNContact serialization problem. I use the Contacts framework to update the AIM field, which is one of the instantMessageAddresses within a single Contact. Here is the simplified code I used:
func updateAIMFieldOn(contact: CNContact, aimValue: String) {
do {
guard let mutableContact = contact.mutableCopy() as? CNMutableContact else {
logger.error("[CM] Couldn't update contact with aim \(aimValue)")
return
}
var updatedAddresses = mutableContact.instantMessageAddresses
updatedAddresses.append(CNLabeledValue(label: "", value: CNInstantMessageAddress(username: aimValue, service: CNInstantMessageServiceAIM)))
mutableContact.instantMessageAddresses = updatedAddresses
let saveRequest = CNSaveRequest()
saveRequest.update(mutableContact)
try CNContactStore().execute(saveRequest)
logger.verbose("Contact's AIM updated successfully!")
} catch {
logger.error("Couldn't update contact")
}
}
And after serializing the contact to data, and then deserializing, the contact got two AIM fields with the same value:
X-AIM;type=pref:some:part:of_my_aim_value
IMPP;X-SERVICE-TYPE=AIM;type=pref:some:part:of_my_aim_value
Why does it work in this manner? Is it possible that ":" char causes that? Format of my aim username is {some:part:of_my_aim_value}. I didn't find any information in the docs.
Thanks!