I have a phonelist application that loads employees from a database and lets users search through them. They have an option to add the contact to their phone. Currently I can add all of the data to the phone as a CNMutableContact(), but if I open up my iOS contact application the image data only works the first time I open the application. If I open it later the images are gone, but all of the other information is correct. Is there something I need to do for saving the image? Does the image need to be stored locally aside from saving it through the save request? The CNMutableContact uses a Data object for the image data. Using Swift 4, iOS target 9.0+
let contact = CNMutableContact()
contact.givenName = givenName
contact.familyName = familyName
contact.imageData = UIImagePNGRepresentation(image)
let store = CNContactStore()
let saveRequest = CNSaveRequest()
saveRequest.add(contact, toContainerWithIdentifier: nil)
do {
try store.execute(saveRequest)
} catch let error {
print(error)
}