Handler of addUIInterruptionMonitor is not called for Alert related to Photos

后端 未结 3 1413
醉梦人生
醉梦人生 2021-02-05 11:39
private func acceptPermissionAlert() {

    _ = addUIInterruptionMonitor(withDescription: \"\") { alert -> Bool in

        if alert.buttons[\"Don’t Allow\"].exists {         


        
3条回答
  •  隐瞒了意图╮
    2021-02-05 12:14

    After adding the interruption monitor, you should continue to interact with the app as if it has not appeared.

    Also note that you have a 'smart quote' in your button identifier, instead of a regular apostrophe.

    let photosAlertHandler = addUIInterruptionMonitor(withDescription: "Photo Permissions") { alert -> Bool in
        if alert.buttons["Don't Allow"].exists {
            alert.buttons.element(boundBy: 1).tapWhenExists()
            return true
        }
        return false
    }
    
    // Do whatever you want to do after dismissing the alert
    let someButton = app.buttons["someButton"]
    someButton.tap() // The interruption monitor's handler will be invoked if the alert is present
    

    When the next interaction happens after the alert appears, the interruption monitor's handler will be invoked and the alert will be handled.

    You should also remove the interruption monitor when you think you're done with it, otherwise it will be invoked for any other alerts that appear.

    removeUIInterruptionMonitor(photosAlertHandler)
    

提交回复
热议问题