I try to reset the camera permission by inject a .notDetermined
value to AVAuthorizationStatus. And I could see in below code AVCaptureDevice.requestAccess(for: .video)
is retriggered, however the camera alert is not presented again on iPhone.
My question is if AVCaptureDevice.requestAccess(for: .video)
will do recheck in some DB for the AVAuthorizationStatus, or it just pops the permission alert, in which way I should have the alert on iPhone. And where the camera permission is stored in iPhone, any persistent storage, and can we clear that storage in code?
And go through several posts already, they advice to uninstall the app, but in automation UI test, we cannot uninstall an app from what I know.
private var isAuthorized: Bool {
get async {
// If UI Test, inject AVAuthorizationStatus = .notDetermined
let status = RuntimeEnv.isUITest ? .notDetermined : AVCaptureDevice.authorizationStatus(for: .video)
var isAuthorized = status == .authorized
if status == .notDetermined {
isAuthorized = await AVCaptureDevice.requestAccess(for: .video)
}
return isAuthorized
}
}
2
Answers
Well, I use prescript in Xcode scheme to uninstall / install the app before each test run. And in this way, camera permission alert could be triggered again.
In general, once a privacy request dialog has been shown, it won’t be shown again.
If you are testing on a simulator and want to reset the device state before the next test run you can use the
xcrun simctl
command in the terminal:xcrun simctl privacy <device> reset all <your.app.bundle>
will reset all privacy permission states for the specified simulator<device>
. You can omit<your.app.bundle>
to reset permissions for all apps on the device.There is no method to reset permission request state on a real device aside from removing and re-installing your app.