0

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)
}
g1231s49
  • 26
  • 6
  • Is it (the image) missing only in your application, or in the default iOS Contacts application is missing too? – Hristo Atanasov Mar 27 '18 at 11:56
  • I load the image from a server in my application on load, I do not even attempt to store them locally. The default iOS Contacts application will display the picture one time, then it disappears. – g1231s49 Mar 28 '18 at 15:10
  • As far as I know, but this is for local images, the image remains in the contact even if you delete the image, so it seems that the contact is making a copy and save it somewhere else. But with not saved locally images it might be different. – Hristo Atanasov Mar 29 '18 at 15:06
  • thank you, I'll try saving it locally and see if that works for me – g1231s49 Mar 29 '18 at 18:38

0 Answers0