0

The app I'm currently working on has to retrieve the ABRecord of a contact using a delegate, since the table for all the associated contacts of an object is in a container view. So far everything works, the only problem is that when I try to retrieve the record again after moving backwards from the AddressBook View Controller the app crashes. Here's a screenshot of the error and the code:

Error on ABRecord

The Code

func showContactInterface(contacto: AnyObject) {
    print(self.addressBookRef)

    let peopleViewController = ABPersonViewController()

    let recordID:ABRecordID = (((contacto as! Contacto).valueForKey("recordRef")?.intValue) as ABRecordID?)!

    var recordRef:ABRecordRef? = ABAddressBookGetPersonWithRecordID(self.addressBookRef, recordID).takeRetainedValue()

    peopleViewController.displayedPerson = recordRef!
    self.navigationController?.pushViewController(peopleViewController, animated: true)
}
karl_m
  • 85
  • 9

2 Answers2

1

I ran into the same problem. I'm not entirely sure why, but changing takeRetainedValue() to takeUnretainedValue() solved it.

var recordRef:ABRecordRef? ABAddressBookGetPersonWithRecordID(self.addressBookRef, recordID).takeUnretainedValue()
Elijah
  • 8,381
  • 2
  • 55
  • 49
0

It seems to be bugged Swift taking data of ABAddressBook, so better solution to fetch some specific data on ObjectiveC and communicate through ObjectiveC_Bridge.

Also look at my article about this issue https://medium.com/@dimpiax/swift-invitephonebook-9a6ef2636124, you can find there link to InvitePhoneBook source also.

dimpiax
  • 12,093
  • 5
  • 62
  • 45