Ios 从Xcode Swift崩溃中的通讯簿中检索公司名称
我试图从通讯簿中检索一些条目,但在“公司”名称值方面遇到了问题 如果通讯簿中的联系人已让公司完成,则其工作正常。但是如果联系人没有,它会使应用程序崩溃(线程1:EXC\u BAD\u ACCESS(Code=1,address=0x0) 我尝试了各种方法来检测nil,但似乎都不起作用。以下是部分代码:-Ios 从Xcode Swift崩溃中的通讯簿中检索公司名称,ios,xcode,swift,Ios,Xcode,Swift,我试图从通讯簿中检索一些条目,但在“公司”名称值方面遇到了问题 如果通讯簿中的联系人已让公司完成,则其工作正常。但是如果联系人没有,它会使应用程序崩溃(线程1:EXC\u BAD\u ACCESS(Code=1,address=0x0) 我尝试了各种方法来检测nil,但似乎都不起作用。以下是部分代码:- func peoplePickerNavigationController( peoplePicker: ABPeoplePickerNavigationController!,
func peoplePickerNavigationController(
peoplePicker: ABPeoplePickerNavigationController!,
didSelectPerson person: ABRecordRef!, property: ABPropertyID, identifier: ABMultiValueIdentifier) {
let addresses: ABMultiValueRef = ABRecordCopyValue(person, property).takeRetainedValue()
let indx = Int(identifier) as CFIndex
let address: NSDictionary = ABMultiValueCopyValueAtIndex(addresses,
indx).takeRetainedValue() as NSDictionary
if address[kABPersonAddressZIPKey as String] != nil {
postcode = address[kABPersonAddressZIPKey as String] as String
}
if address[kABPersonAddressCountryKey as String] != nil {
country = address[kABPersonAddressCountryKey as String] as String
}
if address[kABPersonAddressStateKey as String] != nil {
county = address[kABPersonAddressStateKey as String] as String
}
if address[kABPersonAddressCityKey as String] != nil {
city = address[kABPersonAddressCityKey as String] as String
}
if address[kABPersonAddressStreetKey as String] != nil {
street = address[kABPersonAddressStreetKey as String] as String
}
let recordType = ABRecordCopyValue(person, kABPersonOrganizationProperty)
if recordType != nil {
company = ABRecordCopyValue(person, kABPersonOrganizationProperty)?.takeRetainedValue() as String? ?? ""
} else {
println("just a person, not company")
}
有什么建议吗
非常感谢,
Anthony您使用KabbersonKindProperty设置recordType,但使用KabbersonOrganizationProperty的公司设置recordType的原因是什么?已编辑的帖子。是尝试其他方法停止崩溃后留下的。仍然没有答案或更新吗?