1

I'm developing an app that uses the ABAddressBook APIs to list contacts from the user's address book. When a user uses the app a lot (going in and out of view controllers) the ABAddressBook API stops abruptly responding and an error message is thrown.

AB: Could not compile statement for query (ABCCopyArrayOfAllInstancesOfClassInSourceMatchingProperties): SELECT ROWID, Name, ExternalIdentifier, Type, ConstraintsPath, ExternalModificationTag, ExternalSyncTag, AccountID, Enabled, SyncData, MeIdentifier, Capabilities FROM ABStore WHERE Enabled = ?;

Furthermore, after this error has been thrown and the user tries to navigate to a nib-powered viewcontroller, the app crashes with the following error message:

* Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not load NIB in bundle: 'NSBundle (loaded)' with name 'Sync''

Both these errors only occur after extensive usage which leads me to believe that it's some sort of memory issue. I've noticed with the Memory-debug feature that memory accumulates throughout using the app which seems to be out of the norm but the app is using ARC which means there isn't a lot that could be changed memory-management-wise. I'd greatly appreciate further insight on what could be the root of this problem and how to solve it.

Oskar Larsson
  • 155
  • 1
  • 1
  • 7
  • If you got here from a Google search and are using the new CNContactStore framework in iOS 9, see my answer here: http://stackoverflow.com/a/36506216/52680 – Rich Armstrong Apr 08 '16 at 17:55

1 Answers1

1

In my three apps using the Address Book API, I have run into this problem several times. What I usually did to try fixing it was to check if there was an error creating/saving the ABAddressBookRef every time I used it. This problem is all over Google also.

In order to fix this problem, you need permission to the address book. It seems that you already have done that, or else nothing would work, but just to check your code, look at Programmatically Request Access to Contacts.

The second error likely has something to do with the first one- that is, if you can get rid of the first, the second will disappear. The best solution is to make as few calls to the Address Book as possible- maybe once each time the app loads? Otherwise, this error will keep coming back. The more you call ABAddressBookCreateWithOptions, the more you will likely see the error.

Hopefully that is enough for you to prevent these errors from occurring.

Community
  • 1
  • 1
erdekhayser
  • 6,537
  • 2
  • 37
  • 69