addUIInterruptionMonitor(withDescription:handler :)不能在iOS 10或9上使用

以下testing可以在iOS 11上正常工作。它将取消提醒使用位置服务的权限,然后放大地图中的位置。 在iOS 10或9上,它没有这个,testing仍然成功

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

  let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") let allowBtn = springboard.buttons["Allow"] if allowBtn.exists { allowBtn.tap() } 

我有这个问题,River2202的解决scheme为我工作。

请注意,这不是修复UIInterruptionMonitor的工作方式,而是解除警报的另一种方式。 你也可以删除addUIInterruptionMonitor设置。 你将需要有springboard.buttons["Allow"].existstesting许可警报可能出现的任何地方。 如果可能的话, 迫使它出现在testing的早期阶段,所以你以后不必再担心。

令人高兴的是springboard.buttons["Allow"].exists代码在iOS 11中仍然有效,所以你可以有一个代码path,而不必为iOS 10和iOS 11做一件事情。

顺便说一下,我logging了基本问题(即addUIInterruptionMonitor不工作在iOS 11之前)作为与苹果的错误。 现在已经closures了,所以我想他们承认这是一个错误。