我想从地址簿中删除联系人。我使用此代码从设备的联系人列表中删除联系人。
var recordId = ABRecordID(contact.contactId)
var newContact: ABRecordRef! = ABAddressBookGetPersonWithRecordID(self.add?.adbk, recordId).takeRetainedValue()
var success: Bool = false
var error: Unmanaged<CFErrorRef>? = nil
success = ABAddressBookRemoveRecord(self.add?.adbk, newContact, &error)
println("Adbk addRecord successful? \(success) error \(error)")
createAddressBook()
if success {
success = ABAddressBookSave(self.add?.adbk, &error)
println("Adbk save successful? \(success) error \(error)")
}
但我不明白为什么我在运行时会出现BAD_ACCESS
错误。我停止程序并再次运行,联系人已成功删除。同样在我的代码中写入了SIGKill
信号。我该怎么办?