0

这就是我现在做事的方式:

-(void)vPopulateContact
{
    NSArray * arPeople = (__bridge_transfer NSArray*)(ABAddressBookCopyArrayOfAllPeople( self.addressBook));
    NSMutableArray * arPeople1 = [NSMutableArray array];
    for (id somePeople in arPeople) {
        ABRecordRef ABPerson= (__bridge ABRecordRef)somePeople; //do not transfer ownership
        RCABRecordRef * abRRWrapper = [[RCABRecordRef alloc]init];
        abRRWrapper.abRecordRef=ABPerson;
        [arPeople1 addObject:abRRWrapper];
    }


    NSArray * arPeople2=[arPeople1 sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
        RCABRecordRef * abr1 = (RCABRecordRef*) obj1;
        NSDate * date1=abr1.dDatedAdded;
        RCABRecordRef * abr2 = (RCABRecordRef*) obj2;
        NSDate * date2=abr2.dDatedAdded;
        return [date2 compare:date1];
    }];

    self.allMyContacts=[arPeople2 subarrayWithRange:NSMakeRange(0, MIN(200,arPeople2.count))].mutableCopy;
    [self.tableView reloadData];
}

将整个通讯簿复制到 nsarray 会占用内存。所以我想要一些没有它的东西。

假设我想找到第五个人或类似的东西。我该怎么做?

我应该只复制该人的ID,然后根据ID查找通讯录吗?

4

1 回答 1

2

搜索在搜索通讯簿中进行了说明。例子:

ABAddressBook *AB = [ABAddressBook sharedAddressBook];
ABSearchElement *nameIsSmith = [ABPerson searchElementForProperty:kABLastNameProperty
                                                            label:nil
                                                              key:nil
                                                            value:@"Smith"
                                                       comparison:kABEqualCaseInsensitive];
NSArray *peopleFound = [AB recordsMatchingSearchElement:nameIsSmith];

无法将结果数量限制为给定数量。一种解决方法是匹配字母表中每个字母的姓名首字母。

于 2013-04-27T17:55:15.063 回答