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 にコピーすると、メモリが大量に消費されます。だから私はそれなしで動作するものが欲しい.

5 人目の人物などを見つけたいとします。どうすればいいですか?

個人の 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 に答える