I hit the same issue with xcode 12.2 + iOS 12.4.1, xcode 12.2 + iOS 13.6. The notification is not captured. There is no problem if it is built via xcode 11.7, and run with iOS 12.4.1. The code is:
Code Block | let token = addUIInterruptionMonitor(withDescription: "Notification") { (alert) -> Bool in |
| let allow = alert.buttons["Allow"] |
| if allow.exists { |
| allow.tap() |
| return true |
| } |
| return false |
| } |
| // Interruption won't happen without some kind of action. |
| app.tap() |
| removeUIInterruptionMonitor(token) |
While It works for iOS 13.7/iOS 14.3 + xcode 12.2
We recently upgraded xcode from 11 to 12. It worked before upgrading.
Resolution:
Add following code after above code(above code is still needed for iOS 13.7):
Code Block | app.tap() |
| let springboard = XCUIApplication(bundleIdentifier: "com.apple.springboard") |
| let allowBtn = springboard.buttons["Allow"] |
| if allowBtn.waitForExistence(timeout: 2) { |
| allowBtn.tap() |
| } |
It works for iOS 12.4.1. Please be aware that app.tap() is required to make the app active although we eyes see it. If app.tap() does not work, you could use other code to interact with the app so that the app becomes active, e.g. tap Settings button.
When debugging, please notice the following log should appear. It means the notification is captured. If it does not appear, continue trying to use other code to interact with the app so that the app becomes active, e.g. tap Settings button, until the log appears.
t = 12.30s Wait for com.apple.springboard to idle
t = 12.44s Requesting snapshot of accessibility hierarchy for app with pid 55
t = 12.54s Find: Descendants matching predicate identifier == "NotificationShortLookView" OR elementType == 7