我已经阅读了使用的联系方式CNContact.framework,如下
let contactStore = CNContactStore()
let keys = [CNContactEmailAddressesKey,
CNContactPhoneNumbersKey,
CNContactFormatter.descriptorForRequiredKeys(for: .fullName),
CNContactThumbnailImageDataKey] as! [CNKeyDescriptor]
// The container means
// that the source the contacts from, such as Exchange and iCloud
var allContainers: [CNContainer] = []
do {
allContainers = try contactStore.containers(matching: nil)
// Loop the containers
for container in allContainers {
let fetchPredicate = CNContact.predicateForContactsInContainer(withIdentifier: container.identifier)
do {
let containerResults = try contactStore.unifiedContacts(matching: fetchPredicate, keysToFetch: keys)
for contact in containerResults {
// iterating over contact
}
print("Saving into core data completed")
} catch {
print("Error fetching results for container")
}
}
} catch {
print("Error fetching containers")
}
}
在上面的代码中,我一次读取了所有的联系人。假设我有 10000 个联系人,所有 10K 联系人将立即加载到内存中。有什么方法可以让我通过提供offsetand来获取联系人limit。
假设我想从中获取联系人0-100,然后101-200...
提前致谢。