0
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 to move this to a different thread.

However the 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 what should I do?

Should I create new ABAddressBookRef for different thread? That's the approach for core data right? Create new nsmanagedobjectcontext for different thread?

One solution I can think of is to just create a new address book for each thread

-(ABRecordRef) abRecordRef
{
    ABAddressBookRef _addressBook;
    _addressBook =ABAddressBookCreate();
    ABRecordRef abR = ABAddressBookGetPersonWithRecordID (_addressBook,self.recordID);
    CFRelease(_addressBook);
    return abR;
}

But that means the abR will "survive" without any ABAddressBookRef. Is it even okay?

That makes things even more slow by the way because ABAddressBookCreate actually is quite CPU incentive.

Septiadi Agus
  • 1,775
  • 3
  • 17
  • 26
  • I'm not sure what problem you're trying to solve. If you're only using the reference to read information, why is threading a concern? (Core Data contexts are a lot more complex in terms of possible actions and owned objects.) – Phillip Mills May 20 '13 at 11:46

1 Answers1

1

The docs state:

Important: You must ensure that an instance of ABAddressBookRef is used by only one thread.

So yes, you will have to create one per thread. You should probably be clearer about what your actual problem is however, then we can suggest some more suitable solutions.

Tark
  • 5,153
  • 3
  • 24
  • 23