r/softwaretesting • u/math_the_witch • 1h ago
Testing iOS permission cases with simctl privacy: a command that ran isn't proof of what the app sees
The two permission cases I'd never skip are the app that hasn't asked yet and the app that was told no. Reinstalling to reach either one is slow, so in the Simulator I set the state with simctl privacy and relaunch.
# copy the UDID from this list
xcrun simctl list devices booted
UDID=<device-udid>
APP=com.example.app
# not asked yet: the app should prompt again
xcrun simctl privacy "$UDID" reset photos "$APP"
xcrun simctl launch --terminate-running-process "$UDID" "$APP"
# denied: the app should explain what's missing and not dead-end
xcrun simctl privacy "$UDID" revoke photos "$APP"
xcrun simctl launch --terminate-running-process "$UDID" "$APP"
grant is the third action and covers the allowed case without a prompt. Check which service you actually need: photos and photos-add are separate, and so are location and location-always.
Where it can fool you:
- There is no action that reads the current state. If someone answers a prompt or changes Settings after your command, the script won't know.
- Some permission changes terminate a running app. Set the state before launching, or it can look like a crash.
- With several devices booted,
bootedpicks one of them. Pass the UDID in scripts. grantandrevokerequire a bundle ID, but it's optional forreset. I wouldn't count on a script failing if that argument goes missing.- The built-in help warns that bypassing the normal request can mask bugs, including problems with usage description keys. Keep at least one case that goes through the real prompt.
- Notifications and camera aren't in the service list in Xcode 27.2.
resetalso leaves app data in place, so it isn't a fresh install, and real devices need their own pass.
Disclosure: I make a Mac app, CosmoKit, with a permissions panel that runs these same simctl privacy actions, so it can't read the state back either.
What do you check before the first assertion in a permission case: a status the app reports about itself, the real system prompt driven by UI automation, or only that the setup command succeeded?