private func acceptPermissionAlert() {
_ = addUIInterruptionMonitor(withDescription: "") { alert -> Bool in
if alert.buttons["Don’t Allow"].exists { //doesnt get here second time
alert.buttons.element(boundBy: 1).tapWhenExists()
return true
}
return false
}
}
这不适用于:
在应用程序的开头,它在接受通知权限时运行良好,但在这里...不起作用。
你知道为什么吗?
最佳答案
我发现 addUIInterruptionMonitor 有时不能及时处理警报,或者直到测试完成。如果它不起作用,请尝试使用管理 iOS 主屏幕的 Springboard。您可以从那里访问警报、按钮等,这对于您确切知道警报何时显示的测试特别有用。
所以,像这样:
`let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard")
let alertAllowButton = springboard.buttons.element(boundBy: 1)
if alertAllowButton.waitForExistence(timeout: 5) {
alertAllowButton.tap()
}`
buttons.element(boundBy:1)
将确保您点击右侧的按钮,将 1 更改为 0 以点击左侧,(因为有时 “Don”中的 ' t 允许”
导致问题)。
关于ios - 与照片相关的警报不会调用 addUIInterruptionMonitor 的处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39973904/