在我的应用程序中,我需要用户的联系人列表。我的应用程序在 iPhone 4s、5、5s 上运行良好,但在 iPhone 6 上崩溃。我不知道问题是什么。请帮我。这是我用来获取联系人列表的方法。
let authorizationStatus = ABAddressBookGetAuthorizationStatus()
let addressBookRef: ABAddressBook = ABAddressBookCreateWithOptions(nil, nil).takeRetainedValue()
switch authorizationStatus {
case .Denied, .Restricted:
println("Denied")
case .Authorized:
println("Authorized")
let allContacts = ABAddressBookCopyArrayOfAllPeople(addressBookRef).takeRetainedValue() as Array
for record in allContacts {
let currentContact: ABRecordRef = record
let currentContactName = ABRecordCopyCompositeName(currentContact).takeRetainedValue() as String
let unmanagedPhones = ABRecordCopyValue(currentContact, kABPersonPhoneProperty)
let phones: ABMultiValueRef = Unmanaged.fromOpaque(unmanagedPhones.toOpaque()).takeUnretainedValue() as NSObject as ABMultiValueRef
let countOfPhones = ABMultiValueGetCount(phones)
for index in 0..<countOfPhones{
let unmanagedPhone = ABMultiValueCopyValueAtIndex(phones, index)
let phone: String = Unmanaged.fromOpaque(unmanagedPhone.toOpaque()).takeUnretainedValue() as NSObject as! String
var params : Dictionary = ["name" : currentContactName, "number" : phone]
self.phonesArray.addObject(params)
}
}
case .NotDetermined:
println("Not Determined")
var err: Unmanaged<CFError>? = nil
ABAddressBookRequestAccessWithCompletion(addressBookRef) {
(granted: Bool, error: CFError!) in
dispatch_async(dispatch_get_main_queue()) {
if !granted {
println("Just denied")
} else {
println("Just authorized")
}
}
}
}
最佳答案
尝试将“as String”替换为“as CFString”
关于ios - 应用程序在 iPhone 6 中崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31881003/