iphone - How to know, when this block completes execution -
i trying access abaddressbook properties of person based on recordid, each time, try property, null value.
this code have tried.
abaddressbookref addressbook = null; addressbook = abaddressbookcreatewithoptions(addressbook, nil); abrecordref person = abaddressbookgetpersonwithrecordid(addressbook, (abrecordid) [[object valueforkey:@"recordid"] description]); nsstring *firstname = (__bridge nsstring *)abrecordcopyvalue(person, kabpersonfirstnameproperty); nslog(@"first name %@", firstname); nsstring *lastname = (__bridge nsstring *)abrecordcopyvalue(person, kabpersonlastnameproperty); nsstring *name = [nsstring stringwithformat:@"%@" "%@", lastname, firstname]; nslog(@"full name %@", name);
what doing wrong here?
edit: have kind of figured out above problem. have used. problem having need reload uitableview when block of code completes execution. not able figure out when block completes execution. needs help.
cferrorref myerror = null; abaddressbookref addressbook = abaddressbookcreatewithoptions(null, &myerror); abaddressbookrequestaccesswithcompletion(addressbook, ^(bool granted, cferrorref error) { if (granted) { abrecordid recid = [recordid intvalue]; abrecordref person = abaddressbookgetpersonwithrecordid(addressbook, recid); nsstring *firstname = (__bridge nsstring *)abrecordcopyvalue(person, kabpersonfirstnameproperty); nsstring *lastname = (__bridge nsstring *)abrecordcopyvalue(person, kabpersonlastnameproperty); if(!firstname){ firstname = @""; } if(!lastname){ lastname = @""; } nsstring *name = [nsstring stringwithformat:@"%@ %@", lastname, firstname]; if([firstname length] < 1 && [lastname length] < 1){ name = @"no name"; } self.personname = name; nsdata *imagedata = (nsdata *)cfbridgingrelease(abpersoncopyimagedata(person)); if(imagedata){ self.personimage = [uiimage imagewithdata:imagedata]; } else{ self.personimage = [uiimage imagenamed:@"default.png"]; } nsmutablearray *array = [nsmutablearray array]; [array addobject:self.personname]; [array addobject:self.personimage]; [self.persondetailsarray addobject:array]; [self.tableview reloaddata]; } else { // handle error } });
is updating uielements inside block right way do? if not alternatives.
what have have uitableview loaded/updated after execution of block. couldn't find helpful yet
i think you're creating address book wrong. try creating address book this:
abaddressbookref addressbook = abaddressbookcreate();
you don't need declare null in first line remove that. try person
object , see if returns valid reference.
also, believe abaddressbookcreatewithoptions
has parameters follows:
abaddressbookref abaddressbookcreatewithoptions ( cfdictionaryref options, cferrorref* error );
but instead of options you're passing in reference address book. didn't have luck abaddressbookcreatewithoptions
use abaddressbookcreate
. it's deprecated in ios 6 that's not deal-breaker me.
Comments
Post a Comment