我正在尝试通过UITest文件在设备联系人库中添加联系人。我在plist中添加了隐私使用说明。但它仍然会引发以下错误:
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.
我使用以下代码添加联系人:
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)
相同的代码在从开发目标执行时成功创建了一个联系人。