1

ABAddressBookRef can only be accessed by one thread. I think a good model would be having a thread for ABAddressBookRef in the background, besides the main thread.

How can I ensure that there's only one thread while using NSOperationQueue? Simply setting max concurrency to 1 won't guarantee it to be run on the same thread.

Should I use other unique threads like web threads?

jscs
  • 63,694
  • 13
  • 151
  • 195
Septiadi Agus
  • 1,775
  • 3
  • 17
  • 26

1 Answers1

1

You can manually create a thread and redirect all address book access to it.

You create a thread with something like this (adapted from documentation):

NSThread* myThread = [[NSThread alloc] initWithTarget:[MyThread new]
                                    selector:@selector(myThreadMainMethod)
                                    object:nil];
[myThread start];  // Actually create the thread

Note that for the thread to be useful, you have to implement a run loop in thread's main method.

See example implementation of run loop in this answer.

You are then able to do stuff on this thread using the NSObject's method performSelector:onThread:withObject:waitUntilDone:.

Here's a wrapper library for ABAddressBookRef that implements this concept – RHAddressBook.

Community
  • 1
  • 1
ilya n.
  • 18,398
  • 15
  • 71
  • 89
  • 1
    I don't believe the linked license allows that without a lot of boilerplate. I'll add some code examples, not directly copied from the link. – ilya n. Nov 26 '13 at 23:27