Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 从Xcode Swift崩溃中的通讯簿中检索公司名称_Ios_Xcode_Swift - Fatal编程技术网

Ios 从Xcode Swift崩溃中的通讯簿中检索公司名称

Ios 从Xcode Swift崩溃中的通讯簿中检索公司名称,ios,xcode,swift,Ios,Xcode,Swift,我试图从通讯簿中检索一些条目,但在“公司”名称值方面遇到了问题 如果通讯簿中的联系人已让公司完成,则其工作正常。但是如果联系人没有,它会使应用程序崩溃(线程1:EXC\u BAD\u ACCESS(Code=1,address=0x0) 我尝试了各种方法来检测nil,但似乎都不起作用。以下是部分代码:- func peoplePickerNavigationController( peoplePicker: ABPeoplePickerNavigationController!,

我试图从通讯簿中检索一些条目,但在“公司”名称值方面遇到了问题

如果通讯簿中的联系人已让公司完成,则其工作正常。但是如果联系人没有,它会使应用程序崩溃(线程1:EXC\u BAD\u ACCESS(Code=1,address=0x0)

我尝试了各种方法来检测nil,但似乎都不起作用。以下是部分代码:-

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的原因是什么?已编辑的帖子。是尝试其他方法停止崩溃后留下的。仍然没有答案或更新吗?