iOS reads the local Address Book sample code:

Source: Internet
Author: User

iOS reads the local Address Book sample code:

+ (Nsarray *) readallpeoples{abaddressbookref tmpaddressbook=Nil; Nsmutablearray*array =[[Nsmutablearray alloc] init]; if([[Uidevice currentdevice].systemversion Floatvalue] >=6.0) {Tmpaddressbook=abaddressbookcreatewithoptions (null, NULL); dispatch_semaphore_t Sema= Dispatch_semaphore_create (0); Abaddressbookrequestaccesswithcompletion (Tmpaddressbook,^(BOOLgreanted, cferrorref error)        {dispatch_semaphore_signal (SEMA);        });    Dispatch_semaphore_wait (Sema, dispatch_time_forever); } Else{Tmpaddressbook=abaddressbookcreate (); }     if(!Tmpaddressbook) {        returnNil; } Nsarray*tmppeoples = (__bridge nsarray*) abaddressbookcopyarrayofallpeople (Tmpaddressbook);  for(IDTmppersoninchtmppeoples) {NSString*username =@""; NSString*firstname = (__bridge nsstring*) Abrecordcopyvalue ((__bridge abrecordref) (Tmpperson), kabpersonfirstnameproperty); NSString*lastname = (__bridge nsstring*) Abrecordcopyvalue ((__bridge abrecordref) (Tmpperson), kabpersonlastnameproperty); if([NSString Isvaildstring:firstname] &&[NSString Isvaildstring:lastname]) {UserName= [NSString stringWithFormat:@"%@%@", Lastname,firstname]; }Else if([NSString Isvaildstring:firstname]) {userName= [NSString stringWithFormat:@"%@", FirstName]; }Else if([NSString Isvaildstring:lastname]) {userName= [NSString stringWithFormat:@"%@", LastName]; } abmultivalueref tmpphones=Abrecordcopyvalue (__bridge abrecordref) (Tmpperson), kabpersonphoneproperty); Nsinteger Photocount=Abmultivaluegetcount (Tmpphones); if(Photocount <5) {             for(Nsinteger j =0; J < Photocount; J + +) {NSString*tmpphonestr = (__bridge nsstring*) Abmultivaluecopyvalueatindex (Tmpphones, J); Ittdinfo (@"telphone:%@", TMPPHONESTR); NSString*telphone = [Tmpphonestr stringbyreplacingoccurrencesofstring:@"-"Withstring:@""]; if([commonutils Checkphonenuminput:telphone]) {Addressbookmodel*model =[[Addressbookmodel alloc] init]; Model.username=UserName; Model.telphone=Telphone;                [Array Addobject:model];    }}} cfrelease (Tmpphones);        } cfrelease (Tmpaddressbook); returnArray;}


+ (BOOL) checkphonenuminput: (nsstring *) telephone

{

nsstring *mobile = @ "^1[34578][0-9]{9}$";

nspredicate *regextestmobile = [nspredicate predicatewithformat:@ "Self MATCHES%@", MOBILE];

return [regextestmobile evaluatewithobject: telephone];

}



iOS reads the local Address Book sample code:

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.