addUIInterruptionMonitor() not working on device running iOS 14.0.1
Asked Answered
O

3

8

Since upgrading my device (iPhone 11) to iOS 14.0.1, I have found addUIInterruptionMonitor() to not be triggered at all. It was working before on iOS 13.4.1, which was the last version I had installed.

My code:

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

Nothing in my code has changed since upgrading - the only thing that has changed is the iOS version installed. Has anyone else encountered similar?

Optical answered 29/9, 2020 at 20:4 Comment(1)
Anyone has fixed it?Refuge
C
0

I've got it working with this code:

XCUIApplication.otherElements.firstMatch.swipeLeft()

or

app.otherElements.firstMatch.swipeLeft()

The solution was to use the otherElements.firstMatch. Somehow there where only otherElements inside the XCUIApplication view hierarchy. You can use tap-event or the swipe-event. I find the swipe-event least destructive for the UITest state.

Cyclometer answered 22/2, 2022 at 8:30 Comment(0)
T
0

I resolved it by just sleep the execution 10s.

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()

Throughcomposed answered 12/3, 2022 at 19:9 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Dill
H
0

First of all I would suggest you put the interruption monitor in your setUp() function:

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
 }
}

Second - if adding a sleep resolves your issue to me this means that this isn't a problem with the iOS version but the behaviour of your application on this iOS version. I've had a similar problem where the dummy tap that should trigger the UIInterruptionMonitor was actually being executed before the prompt has appeared which lead to not handling the prompt. You could create a small expectation that waits for either your app loading(by checking some element is present) or until the prompt has appeared and then perform the dummy tap.

Helfand answered 8/4, 2022 at 8:40 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.