iOS 14.0.1设备上addUIInterruptionMonitor()无法正常工作

7
自从将我的设备(iPhone 11)升级到iOS 14.0.1后,我发现addUIInterruptionMonitor()根本没有被触发。 在之前的iOS 13.4.1上它是有效的,那是我安装的最后一个版本。
我的代码:
addUIInterruptionMonitor(withDescription: "App Would Like to Send You Notifications") { (alert) -> Bool in
    if alert.buttons["Allow"].exists {
        alert.buttons["Allow"].tap()
        return true
    }
    return false
}

XCUIApplication().tap()  // interacting with the app to trigger the interruption monitor

自从我升级后,我的代码没有发生任何变化-唯一改变的是安装的iOS版本。有其他人遇到类似的问题吗?


1
有人修好了吗? - DoN1cK
3个回答

0

我用这段代码解决了问题:

XCUIApplication.otherElements.firstMatch.swipeLeft()

或者

app.otherElements.firstMatch.swipeLeft()

解决方案是使用otherElements.firstMatch。不知何故,在XCUIApplication视图层次结构中只有otherElements。您可以使用tap事件或swipe事件。我发现swipe事件对UITest状态的破坏最小。

0

我通过让程序休眠10秒来解决了这个问题。

Darwin.sleep(10)
addUIInterruptionMonitor(withDescription: "App Would Like to Send You Notifications") { (alert) -> Bool in
    if alert.buttons["Allow"].exists {
        alert.buttons["Allow"].tap()
        return true
    }
    return false
}

XCUIApplication().tap()


1
你的回答可以通过提供更多支持信息来改进。请编辑以添加进一步的细节,例如引用或文档,以便他人可以确认你的答案是正确的。您可以在帮助中心找到有关如何编写良好答案的更多信息。 - Community

0
首先,我建议您将中断监视器放置在setUp()函数中:
override func setUp() {
 addUIInterruptionMonitor(withDescription: "App Would Like to Send You Notifications") { (alert) -> Bool in
     if alert.buttons["Allow"].exists {
         alert.buttons["Allow"].tap()
         return true
     }
     return false
 }
}

第二点 - 如果添加睡眠解决了您的问题,那么这意味着这不是iOS版本的问题,而是您的应用在此iOS版本上的行为。我曾经遇到过类似的问题,即虚拟点击应该触发UIInterruptionMonitor,但实际上是在提示框出现之前执行的,导致无法处理提示框。您可以创建一个小期望,等待您的应用程序加载(通过检查某些元素是否存在)或直到提示框出现,然后执行虚拟点击。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接