如何从iOS中的XCTestCase文件访问联系人

时间:2018-03-05 10:33:35

标签: ios iphone xcode xctestcase cncontactstore

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

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

0 个答案:

没有答案