1

我正在尝试通过 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)

从开发目标执行时,相同的代码成功地创建了一个联系人。

4

0 回答 0