I am trying to add a contact in device contact library through UITest file. I have added the privacy usage description in plist. But it still throws the following error :
This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSContactsUsageDescription key with a string value explaining to the user how the app uses this data.
I am using following code to add the contact :
let newContact = CNMutableContact()
newContact.givenName = "XYZ"
newContact.phoneNumbers = [CNLabeledValue(
label: CNLabelPhoneNumberiPhone,
value: CNPhoneNumber(stringValue: "12345678"))]
newContact.organizationName = "abc"
// Saving contact
let saveRequest = CNSaveRequest()
let store = CNContactStore()
saveRequest.add(newContact, toContainerWithIdentifier:nil)
try! store.execute(saveRequest)
Same code successfully creates a contact when executed from development target.