1

Is there an official way to grant/examine/revoke the "user tracking" permission to/of an iOS app on the simulator during testing?

This is the permission that corresponds to the NSUserTrackingUsageDescription entry in the info.plist, and the dialog that pops up during runtime that reads:

Allow "YourApp" to track your activity across other companies' apps and websites?

Currently running on an iPhone 14 Pro simulator running iOS 16.2. Lacking an official way, what other solutions exist?

Note that granting all permissions via simctl does not appear to do the trick, e.g.:

xcrun simctl privacy $DEVICE_ID grant all $BUNDLE_ID

does not grant the tracking permission to the app: the user is still prompted for this permission even after executing that command.

Ideally, I'd like to be able to: grant the permission to the app, examine if the permission has been granted, and revoke the granted permission.

Amos Joshua
  • 1,601
  • 18
  • 25

2 Answers2

1

Here is one solution that involves manipulating the TTC.db database of the simulator, as mentioned in this answer or this gist. It's not very official and I hope someone has a better solution.

Given a device id[1] DEVICE_ID, the database containing certain app permissions should be located at:

# macos 13, xcode 14.2, iOS 16.2
~/Library/Developer/CoreSimulator/Devices/$DEVICE_ID/data/Library/TCC/TCC.db

Then using the sqlite3 client, we can examine the permissions for our app with BUNDLE_ID like so:

sqlite3 ~/Library/Developer/CoreSimulator/Devices/$DEVICE_ID/data/Library/TCC/TCC.db "SELECT * FROM access WHERE client = '$BUNDLE_ID'"        

The result looks something like:

kTCCServiceUserTracking|<BUNDLE_ID>|0|2|2|1||||UNUSED||0|<TIMESTAMP>
kTCCServiceAll|<BUNDLE_ID>|0|2|4|1|||0|UNUSED||0|<TIMESTAMP>

Where the presence of the lines indicates the permission has been granted. If a line is missing, it hasn't been granted.

We can remove all permissions like so:

sqlite3 ~/Library/Developer/CoreSimulator/Devices/$DEVICE_ID/data/Library/TCC/TCC.db "DELETE FROM access WHERE client = '$BUNDLE_ID'"  

Finally we can grant the tracking permission like so:

TIMESTAMP=$(date +%s)
sqlite3 ~/Library/Developer/CoreSimulator/Devices/$DEVICE/data/Library/TCC/TCC.db "INSERT INTO access VALUES ('kTCCServiceUserTracking', '$BUNDLE_ID', 0, 2, 4, 1, null, null, 0, 'UNUSED', null, 0, $TIMESTAMP)"

[1] the udid entry of one of the values in xcrun simctl list devices --json

Amos Joshua
  • 1,601
  • 18
  • 25
0

You can use AppleSimulatorUtils:

First install it:

brew tap wix/brew
brew install applesimutils

Then run, where $BUNDLE_ID changed to you

applesimutils --booted --bundle $BUNDLE_ID --setPermissions "userTracking=YES"

Difference with Amos Joshuae method: after this command, SpringBoard will restart to make the changes take effect