Is it possible to grant access to the native address book (NAB) on iOS 7.0 Simulator programmatically? I am writing xctest Unit Tests that need write access to NAB. The unit tests are run on iOS 7.0 Simulator and are part of Continuous Integration process and doesn't involve any user interaction.
Currently unless the user grants access explicitly via the “TestApp” Would like to Access Your Contacts alert, access to NAB is denied.
In the spirit of sharing I am going to answer my own question. Among other permissions, Address Book access permission is stored in
TCC.db
database that is located in/Library/TCC/
in the iPhone Simulator folder.Permissions are stored in the
access
table in TCC.db database.access
table schema is:The fields we are interested in are:
service
- the permission typeclient
- the app identifierallowed
- permission granted?In order to grant Access Book permission, and appropriate record should be inserted into the
access
table (or updated if already exists). After the record was either inserted or updated the table should look like that:I've wrote the following method to update the TCC.db database.
Because of the obvious reasons, the target should be linked with libsqlite3.dylib.
DO NOT forget to change the app identifier (com.your.app.id) in the
updateSql
to your app identifier.This Cocoapod works great for testing purposes: https://github.com/plu/JPSimulatorHacks