แก้ไข

แชร์ผ่าน


iOS privacy alerts

Important

Visual Studio App Center is scheduled for retirement on March 31, 2025. While you can continue to use Visual Studio App Center until it is fully retired, there are several recommended alternatives that you may consider migrating to.

Learn more about support timelines and alternatives.

Note

This article doesn't address alerts created with UIAlertViewController in applications. They can be handled directly by appropriate test queries. Rather this article is about alerts generated by iOS that standard UI queries can't handle.

While an iOS application is executing, the operating system may display alerts to the user at various times as the application attempts to activate or access Apple Push Notifications, Location Services, Contacts, the device Microphone or Camera, and so on, to request permission. These popups are sometimes called alerts, System Alerts, System Popups, Springboard Alerts, or Privacy Dialogs. When these requests are accepted, that acceptance state is persisted so the user usually won't see that alert again for that app on the device.

When the app is first installed, these alerts will need to be addressed. Tests running locally may not find alerts if the requests have been previously accepted.

When your tests execute in App Center Test, they're running on pristine devices and alerts are triggered when the application attempts to access protected services or features.

Handling these alerts in App Center Test varies by the test framework.

Xamarin.UITest and Calabash iOS

Xamarin.UITest and Calabash automatically accept alerts that they know about. Known alerts are based on text matching. If you have a case where a SpringBoard alert isn't dismissed, search for the alert title in the DeviceAgent.json files.

$ cd DeviceAgent.iOS
$ git pull
$ find Server/Resources.xcassets -name "alerts.json" -exec grep -q "to access your location" {} \; -print
Server/Resources.xcassets/springboard-alerts/springboard-alerts-en_GB.dataset/alerts.json
Server/Resources.xcassets/springboard-alerts/springboard-alerts-en_AU.dataset/alerts.json
Server/Resources.xcassets/springboard-alerts/springboard-alerts-en.dataset/alerts.json

If your application has alerts that aren't in that file, go to ? > Contact Support in the App Center website to get them added. If they're already in that file, there may be some problem with the device configuration, which should be reported as a bug to App Center Test Support.

Note

You may notice DismissSpringboardAlerts() in the Xamarin.UITest API. DismissSpringboardAlerts() is a method that Xamarin.UITest uses internally. There isn't generally a need to call DismissSpringboardAlerts() in user test code.

XCUITest versus UIAutomation

Xamarin.UITest and Calabash use one of two Apple test frameworks for interacting with the devices.

  • If you're running tests locally, then the Apple Test Framework is XCUITest.
  • If you're running tests in App Center Test, with iOS 10 or newer, then the Apple Test Framework is XCUITest.
  • If you're running tests in App Center Test, with iOS versions older than iOS 10, then you're using Apple's UIAutomation.

Testing with UIAutomation requires a delay in the application before the first Alert occurs in order for Apple's UIAutomation framework to take control of the application under test. If this is an issue for your application and tests, see Managing Privacy Alerts: Location Services, APNS, Contacts.

Calabash iOS

In addition to handling alerts automatically like Xamarin.UITest, Calabash also allows for managing alerts manually.

  • To check if an alert is showing, and query its attributes, see /springboard-alert in QueryRoutes.m.
  • To dismiss an alert, by touching the button with a given title, see /set-dismiss-springboard-alert in GestureRoutes.m.
  • To dismiss known alerts, and to toggle automatic dismissal, see /dismiss-springboard-alerts and /set-dismiss-springboard-alerts-automatically in MetaRoutes.m. An exception is raised if /dismiss-spring-board-alerts is called and comes across an unknown alert.

This Calabash iOS code snippet shows how to use these methods:

...
# Turn off automatic alert dismissal
device_agent.dismiss_springboard_alerts_manually!

# Do whatever triggers the alert, then wait for the alert
# that may or may not appear.
begin
  device_agent.wait_for_springboard_alert(10) # timeout is optional
  device_agent.dismiss_springboard_alert("OK")
rescue RuntimeError
   # Alert didn't appear, so there's nothing to do
end
...

# Turn automatic dismiss back on
dismiss_springboard_alerts_automatically!

Appium

See the Appium documentation for Alert.

XCUITest

See the Apple documentation for Monitoring UI Interruptions.

Getting help

You can always contact us through the ? icon in the upper-right hand corner. We don't provide 24/7 support, but will reply as soon as we can.

If you want help with a test run, navigate to the test run in question and copy the URL from your browser and paste it into the support conversation. A test run URL looks like something like https://appcenter.ms/orgs/OrgName/apps/App-Name/test/runs/77a1c67e-2cfb-4bbd-a75a-eb2b4fd0a747.