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:
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)
}
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()
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.