ios - addUIInterruptionMonitor(withDescription :handler:) not working on iOS 10 or 9

标签 ios swift xctest xcode-ui-testing

以下测试在 iOS 11 上运行良好。它消除了请求权限使用位置服务的警报,然后放大 map 。在 iOS 10 或 9 上,它什么都不做,测试仍然成功

func testExample() {
    let app = XCUIApplication()

    var handled = false
    var appeared = false

    let token = addUIInterruptionMonitor(withDescription: "Location") { (alert) -> Bool in
        appeared = true
        let allow = alert.buttons["Allow"]
        if allow.exists {
            allow.tap()
            handled = true
            return true
        }

        return false
    }

    // Interruption won't happen without some kind of action.
    app.tap()

    removeUIInterruptionMonitor(token)
    XCTAssertTrue(appeared && handled)
}

有没有人知道原因和/或解决方法?

这是一个可以重现问题的项目:https://github.com/TitouanVanBelle/Map

更新

Xcode 9.3 Beta 的变更日志显示如下

XCTest UI interruption monitors now work correctly on devices and simulators running iOS 10. (33278282)

最佳答案

let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") 

let allowBtn = springboard.buttons["Allow"]
if allowBtn.waitForExistence(timeout: 10) {
    allowBtn.tap()
}

更新.exists.waitForExistence(timeout: 10),详情请查看评论。

关于ios - addUIInterruptionMonitor(withDescription :handler:) not working on iOS 10 or 9,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45228343/

相关文章:

ios - 无法在 iOS 6 中保存 EKReminder

ios - 在 Swift 中设置可拖动项目的限制

uiwebview - 使用 Xcode UI 测试测试 UIWebView

ios - React Native iOS 没有构建

ios - iOS 设备之间的字节顺序是否相同,这是否使得 iOS 设备之间不需要使用 htonl 和 ntohl?

ios - 从上到下方向呈现 View Controller

ios - 如何平均固定宽度?

ios - 如何在 UITabBarController 中交换 ViewController

ios - 从 Swift 中的模拟调用 super

ios - 如何检查 MPMediaItem 是否只有音频的 MPMediaType?