Work with AddressBook without blocking the main thread
Work with AddressBook without blocking the main thread
- Subject: Work with AddressBook without blocking the main thread
- From: Peter Tomaselli <email@hidden>
- Date: Sat, 25 Apr 2015 20:06:22 -0400
Hi there. I’m writing my first iPhone application and trying to figure out how to best work—asynchronously—with the AddressBook API. I’m building against iOS 8.
I’m not experienced with Cocoa, but based on the docs, as well as seemingly-credible SO answers (particularly this one[0]), my understanding is that the ABAddressBook APIs are not only thread-unsafe but also thread… affine? Or whatever? In other words, it is not enough to access AddressBook objects in a serial fashion, they must actually be accessed from the same thread on which they were created.
The crux of my problem is that, according to the docs, ABAddressBookRequestAccessWithCompletion’s completion handler “is called on an arbitrary queue”. However, ABAddressBookRequestAccessWithCompletion accepts as an argument an ABAddressBookRef that, presumably, has already been created.
I’m not sure how to proceed here. GCD serial queues can guarantee serial access to stuff, but it doesn’t seem like they provide any guarantees about your code executing on any one thread in particular. So, it doesn’t seem like GCD helps me here.
Finally, just to clarify my question a little:
- I am interested in doing this “the right way”, and without any third-party libraries, as a learning experience.
- I’d like to end up with a simple wrapper class that accepts blocks (I imagine) of the type void (^)(ABAddressBookRef) and executes them—abstracting away the authorization checking stuff, which I think I understand—without blocking the UI.
Thanks for any suggestions!
Peter
[0] http://stackoverflow.com/a/10844781
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden