I am trying to speed up syncing contacts all the contacts on the device to my app. At the moment its blocking the main thread when syncing the contacts.

I added the individual contact setup in an NSInvocationOperation and adding that to a NSOperationQueue.

I know that you can only access the UI in the main thread. What can't you access in regards to Address book data?

有帮助吗?

解决方案

The address book framework is generally safe to use from a background thread but their are pitfalls. The important caveats are mentioned in the documentation:

Important Instances of ABAddressBookRef cannot be used by multiple threads. Each thread must make its own instance.

and

Important Record objects cannot be passed across threads safely. Instead, you should pass the corresponding record identifier. See “Using Record Identifiers” for more information.

Note that just because NSInvocationOperation are on the same NSOperationQueue does not guarantee that they will be executed on the same thread.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top