Xcode 7.3 및 Swift 2.2를 사용하고 있습니다. 장치의 모든 연락처를 가져 와서 배열에 저장하려고합니다. 그것은 시뮬레이터에서 잘 작동하지만 디바이스에서 테스트 할 때 매우 느립니다 (378 개의 접점 포함). 그렇게하는 데 20 ~ 25 초 정도 걸립니다. 다양한 중단 점을 넣고 전화에서 연락처를 가져 오는 데 최대 시간이 걸리는 것으로 나타났습니다. 생성 된 배열에서 테이블보기로 연락처를 표시하는 데는 시간이 전혀 걸리지 않습니다. 내 코드는 다음과 같습니다연락처 프레임 워크를 사용하여 느린 연락처 가져 오기
var results: [CNContact] = []
func retrieveContactsWithStore() {
let contactStore = CNContactStore()
var i = 0
var allContainers: [CNContainer] = []
do {
allContainers = try contactStore.containersMatchingPredicate(nil)
} catch {
print("Error fetching containers")
}
for container in allContainers {
let fetchPredicate = CNContact.predicateForContactsInContainerWithIdentifier(container.identifier)
do {
let containerResults = try contactStore.unifiedContactsMatchingPredicate(fetchPredicate, keysToFetch: [
CNContactGivenNameKey, CNContactFamilyNameKey, CNContactPhoneNumbersKey])
results.appendContentsOf(containerResults)
} catch {
print("Error fetching results for container")
}
}
다음은 내 테이블보기를 채우는 방법입니다.
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCellWithIdentifier("Cell", forIndexPath: indexPath)
cell.textLabel?.text = results[indexPath.row].givenName
cell.detailTextLabel?.text = ((results[indexPath.row].phoneNumbers[0].value as? CNPhoneNumber)?.valueForKey("digits") as? String)
return cell
}
디버그 네비게이터에서도 CPU가 98-99 %로 급증합니다. 에너지 영향 - 매우 높음. 연락처를 가져 오면 정상 값으로 돌아갑니다.
CNContactPhoneNumbersKey를 가져 오는 데 많은 시간이 걸리는 것으로 나타났습니다. CNContactGivenNameKey를 가져 오는 것만으로 빠릅니다 (2-3 초). 이 문제에 대한 해결책이 있습니까?
아야. 내 사용자가 기대할 것으로 보이는 것과 같지 않습니다! – Randy
사용자별로 다릅니다. 개발자는 무엇을 할 수 있습니까? 그러나 그것은 끔찍한 UX에 포함될 것입니다. –