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: