addUIInterruptionMonitor(withDescription:handler :)无法在iOS 10或9上运行

Tit*_*eul 15 ios xctest swift xcode-ui-testing

以下测试在iOS 11上运行正常.它解除了警告,要求使用位置服务的权限,然后放大地图.在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)
}
Run Code Online (Sandbox Code Playgroud)

有没有人知道为什么和/或解决方法?

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

更新

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

XCTest UI interruption monitors now work correctly on devices and simulators running iOS 10. (33278282)
Run Code Online (Sandbox Code Playgroud)

Riv*_*202 31

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

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

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