objective c - How to properly use address book for background thread? -
uiimage* image; if(abpersonhasimagedata(self.abrecordref)){ image = [uiimage imagewithdata:(__bridge_transfer nsdata *)abpersoncopyimagedata(self.abrecordref)]; } -(abrecordref) abrecordref { abrecordref abr = abaddressbookgetpersonwithrecordid ([rcabaddressbookhandler addressbook],self.recordid); return abr; } i want move different thread.
however definition of addressbook is
+(abaddressbookref) addressbook { return [rcabaddressbookhandler singleton].addressbook; } and
it's declared as
@property (nonatomic) abaddressbookref addressbook; and that's not type safe.
so should do?
should create new abaddressbookref different thread? that's approach core data right? create new nsmanagedobjectcontext different thread?
one solution can think of create new address book each thread
-(abrecordref) abrecordref { abaddressbookref _addressbook; _addressbook =abaddressbookcreate(); abrecordref abr = abaddressbookgetpersonwithrecordid (_addressbook,self.recordid); cfrelease(_addressbook); return abr; } but means abr "survive" without abaddressbookref. okay?
that makes things more slow way because abaddressbookcreate quite cpu incentive.
the docs state:
important: must ensure instance of
abaddressbookrefused 1 thread.
so yes, have create 1 per thread. should clearer actual problem however, can suggest more suitable solutions.
Comments
Post a Comment