iOS 隱私權警示
重要
Visual Studio App Center 已排定於 2025 年 3 月 31 日淘汰。 雖然您可以繼續使用 Visual Studio App Center,直到它完全淘汰為止,但有數個建議您考慮移轉至的建議替代方案。
注意
本文不會解決在應用程式中建立的 UIAlertViewController
警示。 您可以透過適當的測試查詢直接處理它們。 本文與 iOS 所產生的警示有關,但標準 UI 查詢無法處理。
當 iOS 應用程式正在執行時,操作系統可能會在應用程式嘗試啟用或存取 Apple Push Notifications、Location Services、Contacts、裝置麥克風或相機等要求許可權時,向使用者顯示警示。 這些彈出視窗有時稱為警示、系統警示、系統快顯、Springboard 警示或隱私權對話方塊。 接受這些要求時,會保存該接受狀態,因此使用者通常不會再次看到該裝置上該應用程式的警示。
第一次安裝應用程式時,必須解決這些警示。 如果先前已接受要求,則執行於本機的測試可能找不到警示。
當您的測試在 App Center 測試中執行時,當應用程式嘗試存取受保護的服務或功能時,會在裝置上執行,並觸發警示。
在 App Center 測試中處理這些警示會因測試架構而異。
Xamarin.UITest 和擷取物件 iOS
Xamarin.UITest 和擷取Ash 會自動接受他們知道的警示。 已知警示是以文字比對為基礎。 如果您有未關閉 SpringBoard 警示的情況,請在 DeviceAgent.json檔案中搜尋警示標題。
$ 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
如果應用程式有不在該檔案中的警示,請移至 ? > 請連絡 App Center 網站中的支持人員以新增它們。 如果他們已經在該檔案中,裝置組態可能會有一些問題,這應該會回報為 App Center 測試支援的錯誤。
注意
您可能會在 Xamarin.UITest API 中注意到 DismissSpringboardAlerts()
。 DismissSpringboardAlerts()
是 Xamarin.UITest 在內部使用的方法。 使用者測試程式代碼中通常不需要呼叫 DismissSpringboardAlerts()
。
XCUITest 與 UIAutomation
Xamarin.UITest 和一個擷取物件會使用兩個 Apple 測試架構的其中一個來與裝置互動。
- 如果您要在本機執行測試,則 Apple Test Framework 為 XCUITest。
- 如果您在 App Center 測試中執行測試,且 iOS 10 或更新版本,則 Apple Test Framework 為 XCUITest。
- 如果您在 App Center 測試中執行測試,且 iOS 版本比 iOS 10 還舊,則您使用的是 Apple 的 UIAutomation。
使用UIAutomation進行測試需要應用程式在發生第一個警示之前延遲,Apple 的UIAutomation架構才能控制受測的應用程式。 如果這是您的應用程式和測試的問題,請參閱 管理隱私權警示:位置服務、APNS、連絡人。
擷取 iOS
除了自動處理 Xamarin.UITest 之類的警示之外,也允許手動管理警示。
- 若要檢查警示是否顯示,並查詢其屬性,請參閱
/springboard-alert
QueryRoutes.m。 - 若要關閉警示,請連絡具有指定標題的按鈕,請參閱
/set-dismiss-springboard-alert
GestureRoutes.m。 - 若要關閉已知的警示,以及切換自動關閉,請參閱
/dismiss-springboard-alerts
MetaRoutes.m 中的 和/set-dismiss-springboard-alerts-automatically
。 如果/dismiss-spring-board-alerts
呼叫 且發生未知的警示,就會引發例外狀況。
此擷取物件 iOS 代碼段示範如何使用下列方法:
...
# 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
請參閱 Appium 檔以取得警示。
XCUITest
請參閱 Apple 檔以 監視 UI 中斷。
取得說明
您一律可以透過 右上角的 ? 圖示與我們連絡。 我們不會提供 24/7 的支援,但會儘快回復。
如果您想要測試回合的協助,請流覽至有問題的測試回合,並從瀏覽器複製 URL,然後將它貼到支援交談中。 測試回合 URL 看起來像這樣 https://appcenter.ms/orgs/OrgName/apps/App-Name/test/runs/77a1c67e-2cfb-4bbd-a75a-eb2b4fd0a747。