ios - UIAddressBook in UITableView with NSObjectClass -
i need make uitableview
fetches address book contents in , uisearchbar
searches address book contents.
i need implementation project
http://www.appcoda.com/search-bar-tutorial-ios7/
but problem here data static , want load address book's data in it.
i have created contactdata nsobject class. in following method, creating object each contact. @ end, nsmutablearray named contactarr.
-(void)loadcontacts{
abaddressbookref addressbookref = abaddressbookcreatewithoptions(null, null); if (abaddressbookgetauthorizationstatus() == kabauthorizationstatusnotdetermined) { abaddressbookrequestaccesswithcompletion(addressbookref, ^(bool granted, cferrorref error) { abaddressbookref addressbook = abaddressbookcreatewithoptions(null, null); //nslog(@"%@", addressbook); }); } else if (abaddressbookgetauthorizationstatus() == kabauthorizationstatusauthorized) { cferrorref *error = null; abaddressbookref addressbook = abaddressbookcreatewithoptions(null, error); cfarrayref allpeople = abaddressbookcopyarrayofallpeople(addressbook); cfindex numberofpeople = abaddressbookgetpersoncount(addressbook); for(int = 0; < numberofpeople; i++) { abrecordref person = cfarraygetvalueatindex( allpeople, ); nsstring *firstname = (__bridge nsstring *)(abrecordcopyvalue(person, kabpersonfirstnameproperty)); nsstring *lastname = (__bridge nsstring *)(abrecordcopyvalue(person, kabpersonlastnameproperty)); contactdata *dataobj = [[contactdata alloc]init]; nsstring *name = @" "; if ([firstname length]>0) { if ([lastname length]>0) { name = [nsstring stringwithformat:@"%@ %@",firstname,lastname]; } else{ name = firstname; } } else{ name = @" "; } abmultivalueref phonenumbers = abrecordcopyvalue(person, kabpersonphoneproperty); [[uidevice currentdevice] name]; //nslog(@"\n%@\n", [[uidevice currentdevice] name]); nsstring *phonenumber = @" "; (cfindex = 0; < abmultivaluegetcount(phonenumbers); i++) { phonenumber = (__bridge_transfer nsstring *) abmultivaluecopyvalueatindex(phonenumbers, i); } abmultivalueref emails = abrecordcopyvalue(person, kabpersonemailproperty); [[uidevice currentdevice] name]; nsstring *email; //= @" "; (cfindex = 0; < abmultivaluegetcount(emails); i++) { email = (__bridge_transfer nsstring *) abmultivaluecopyvalueatindex(emails, i); } abmultivalueref addresses = abrecordcopyvalue(person, kabpersonaddressproperty); nsstring *address = @" "; nsmutabledictionary* addressdict = [[nsmutabledictionary alloc]init]; (cfindex = 0; < abmultivaluegetcount(addresses); i++) { addressdict = (__bridge_transfer nsmutabledictionary *) abmultivaluecopyvalueatindex(addresses, i); //nslog(@"address = %@", addressdict); nsstring * street = [addressdict objectforkey:@"street"]; nsstring * city = [addressdict objectforkey:@"city"]; nsstring * state = [addressdict objectforkey:@"state"]; nsstring *country = [addressdict objectforkey:@"country"]; if (country.length>0 || state.length>0 || city.length>0 || street.length>0) { if (country.length>0 && state.length>0) { address = [nsstring stringwithformat:@"%@, %@", state,country]; } else if(country.length>0 && city.length>0){ address = [nsstring stringwithformat:@"%@, %@", city,country]; } else if (state.length>0 && street.length>0){ address = [nsstring stringwithformat:@"%@, %@", street,country]; } else if (state.length>0 && city.length>0){ address = [nsstring stringwithformat:@"%@, %@", city,state]; } else if (state.length>0 && street.length>0){ address = [nsstring stringwithformat:@"%@, %@", street,state]; } else if (city.length>0 && street.length>0){ address = [nsstring stringwithformat:@"%@, %@", street,city]; } else if (country.length>0){ address = country; } else if (state.length>0){ address = state; } else if (city.length>0){ address = city; } } else{ address = @" "; } } //nslog(@"address = %@", address); nsdata *imgdata = (__bridge_transfer nsdata *) abpersoncopyimagedatawithformat(person, kabpersonimageformatthumbnail); dataobj.name = name; dataobj.email = email; dataobj.phone = phonenumber; dataobj.imagedata = imgdata; dataobj.address = address; [contactarr addobject:dataobj]; } nslog(@"contacts loaded"); //nslog(@"count = %lu", (unsigned long)contactarr.count); } else { //go settings , allow access use contacts[globalfunction removewaitview]; }
}
Comments
Post a Comment