gpt4 book ai didi

ios - ABAddressBookCopyArrayOfAllPeople 慢

转载 作者:行者123 更新时间:2023-11-29 02:31:21 28 4
gpt4 key购买 nike

我正在编写一个应用程序,我需要在其中读取用户的地址簿并显示他所有联系人的列表。我正在测试的 iPhone 有大约 100 个联系人,加载联系人确实需要很多时间。

ABAddressBookRef addressBook = ABAddressBookCreateWithOptions(NULL, NULL);
NSArray *allContacts = (__bridge NSArray *)ABAddressBookCopyArrayOfAllPeople(addressBook);
ABMultiValueRef phones = NULL;
ABRecordRef person = NULL;
for (int i =0; i < allContacts.count; i++) {
person = (__bridge ABRecordRef)([allContacts objectAtIndex:i]);
if (person != nil) {
phones = ABRecordCopyValue(person, kABPersonPhoneProperty);
if (ABMultiValueGetCount(phones) == 0) {
CFErrorRef error = nil;
ABAddressBookRemoveRecord(addressBook, person, &error);
}
CFRelease(phones);
}
}
CFErrorRef saveError = nil;
ABAddressBookSave(addressBook, &saveError);

ABPeoplePickerNavigationController *picker = [[ABPeoplePickerNavigationController alloc] init];
picker.view.backgroundColor=[UIColor clearColor];
picker.peoplePickerDelegate = self;
picker.delegate=self;
NSArray *displayedItems =
[NSArray arrayWithObject:[NSNumber
numberWithInt:kABPersonPhoneProperty]];
picker.displayedProperties = displayedItems;

最佳答案

您可以使用 performSelectorInBackground:withObject: 在后台线程中执行复制,这样它就不会影响主线程并且您不必在 UI 中等待。

关于ios - ABAddressBookCopyArrayOfAllPeople 慢,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26829840/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com