作者:adfa3sd5f6a | 来源:互联网 | 2023-08-28 04:19
ThereissomeproblemwithAddressBookwhichIcantreproduce,codeworksonmyiPhoneandiPad,th
There is some problem with AddressBook which I can't reproduce, code works on my iPhone and iPad, this happens on client phone and result in app crash. As far as I can see from Crashlytics problem should be in following line:
AddressBook有一些我无法重现的问题,代码可以在我的iPhone和iPad上运行,这种情况发生在客户端手机上并导致应用程序崩溃。据我所知,Crashlytics问题应该在以下几行:
let data = ABPersonCopyImageDataWithFormat(contact, kABPersonImageFormatThumbnail).takeRetainedValue()
Here is complete code for reading address book:
以下是阅读地址簿的完整代码:
var err : Unmanaged? = nil
let addressBookRef : ABAddressBook? = ABAddressBookCreateWithOptions(nil, &err).takeRetainedValue()
if addressBookRef == nil {
print(err)
return
}
let cOntacts= ABAddressBookCopyArrayOfAllPeople(addressBookRef).takeRetainedValue() as NSArray as [ABRecord]
for contact in contacts {
let firstName = ABRecordCopyValue(contact, kABPersonFirstNameProperty)?.takeRetainedValue() as? String
let lastName = ABRecordCopyValue(contact, kABPersonLastNameProperty)?.takeRetainedValue() as? String
var image: UIImage?
if ABPersonHasImageData(contact) {
let data = ABPersonCopyImageDataWithFormat(contact, kABPersonImageFormatThumbnail).takeRetainedValue()
if let img = UIImage(data: data) {
image = img
}
}
…
}
Do you have any suggestions what could happen on clients phone so I can reproduce this error? Is it possible that some contact is corrupt? How should I handle this?
您对客户手机上可能发生的事情有什么建议吗?我可以重现这个错误吗?某些联系是否可能已损坏?我该怎么处理?
I've seen this post Get iOS contact image with ABPersonCopyImageData that ABPersonCopyImageData could return nil, I tried to handle that but app is still crashing.
我看过这篇帖子用ABPersonCopyImageData获取iOS联系人图片,ABPersonCopyImageData可以返回nil,我试图处理,但应用程序仍在崩溃。
2 个解决方案