【问题标题】:addUIInterruptionMonitor() not working on device running iOS 14.0.1addUIInterruptionMonitor() 在运行 iOS 14.0.1 的设备上不起作用
【发布时间】:2020-09-29 20:04:32
【问题描述】:

自从将我的设备 (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 版本。有没有其他人遇到过类似的情况?

【问题讨论】:

  • 有人修过吗?

标签: swift xcode xctest ios14 xcuitest


【解决方案1】:

我已经使用此代码:

XCUIApplication.otherElements.firstMatch.swipeLeft()

app.otherElements.firstMatch.swipeLeft()

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

【讨论】:

    【解决方案2】:

    我只是通过休眠执行 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()
    
    

    【讨论】:

    • 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center
    猜你喜欢
    • 2014-05-25
    • 2017-12-26
    • 2018-09-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多