简体   繁体   English

ABAddressBookGetPersonWithRecordID导致我的应用崩溃

[英]ABAddressBookGetPersonWithRecordID Crashes my App

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. 我当前正在使用的应用程序必须使用委托来检索联系人的ABRecord,因为对象的所有关联联系人的表都在容器视图中。 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. 到目前为止,一切正常,唯一的问题是,当我尝试从AddressBook View Controller向后移动后再次尝试检索记录时,应用程序崩溃了。 Here's a screenshot of the error and the code: 这是错误和代码的屏幕截图:

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)
}

I ran into the same problem. 我遇到了同样的问题。 I'm not entirely sure why, but changing takeRetainedValue() to takeUnretainedValue() solved it. 我不完全确定为什么,但是将takeRetainedValue()更改为takeUnretainedValue()解决了它。

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. Swift似乎要窃听ABAddressBook的数据,因此更好的解决方案是在ObjectiveC上获取一些特定数据并通过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. 另请参阅我关于此问题的文章https://medium.com/@dimpiax/swift-invitephonebook-9a6ef2636124 ,您也可以找到指向InvitePhoneBook源的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM