Fuzzy query for IOS address Book

Source: Internet
Author: User

1, first get the address Book

-(void) readallpeoples

{

[contactsremoveallobjects];

abaddressbookref addressbook =abaddressbookcreatewithoptions(Nil , Nil );

dispatch_semaphore_t sema =dispatch_semaphore_create(0);

abaddressbookrequestaccesswithcompletion(addressbook, ^ (bool granted, Cferrorref Error)

{

dispatch_semaphore_signal (SEMA);

});

dispatch_semaphore_wait(Sema,dispatch_time_forever);

cfarrayref results =abaddressbookcopyarrayofallpeople(addressbook);

for (int i =0; i < cfarraygetcount(results); i++)

{

abrecordref person = Cfarraygetvalueatindex(results, i);

nsstring *lastname = (__bridgensstring*)abrecordcopyvalue (person,kabpersonlastnameproperty );

NSLog (@ "lastname:%@", LastName);

abmultivalueref phone =abrecordcopyvalue(person,kabpersonphoneproperty);

// Read Contact information

for (int k =0; k<abmultivaluegetcount(phone); k++)

{

nsstring * personphone = (__bridgensstring*)abmultivaluecopyvalueatindex(phone , k);

if (LastName = = Nil) {

LastName =@ "";


}

if (Person = = Nil) {

continue;

}

// This sentence is a storage structure, contacts is nsmutablearray*

[contactsaddobject:@[lastname,personphone]];


}

}

Cfrelease (results);

Cfrelease (AddressBook);

[self. TableView reloaddata];

}

2, the name (LastName) and mobile phone number (personphone) fuzzy query

NSPredicate *predicate = [nspredicate predicatewithformat:@ "self[0] contains [CD]%@| | SELF[1] contains [CD]%@ ", user input String, user input string];

filterdata = [[nsarrayalloc] initwitharray: [ contacts filteredarrayusingpredicate :p redicate]];

Filterdata is the result of the query.


Fuzzy query for IOS address Book

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.