2016-10-11 11 views
6
private func acceptPermissionAlert() { 

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

     if alert.buttons["Don’t Allow"].exists { //doesnt get here second time 

      alert.buttons.element(boundBy: 1).tapWhenExists() 

      return true 
     } 

     return false 
    } 
} 

と、このdoesntの仕事に関連するアラートのために呼び出されていません。addUIInterruptionMonitorのハンドラは、写真用

アプリの初めに

enter image description here

通知の許可をaceptingながら、それは完璧に動作しますが、ここでは... doesnt仕事。

あなたはその理由を知っていますか?

+0

どういう意味ですか?私はどこにそれを追加する必要がありますか? –

答えて

9

追加:

app.tap() 

方法の終わりに。

これは、ハンドラーが起動するためにアプリと対話する必要があるためです。

+2

またはapp.swipeUp()をタップすると、アプリで実際に何かが起こる(そしてあなたがしたくない場合) – xaphod

+1

それは私のために働く。これはちょっと変わったものです... "起動するハンドラのためにアプリケーションと対話する必要があります。" はどこかに記載されていますか? – cornr

+0

このバグのレーダーはありますか? –

1

割り込みモニタを追加した後も、まだ表示されていないかのようにアプリケーションと対話する必要があります。

また、通常のアポストロフィではなく、ボタン識別子に「スマートな見積もり」があります。警告が表示された後、次の相互作用が起こると

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 

、中断モニタのハンドラが呼び出されるとアラートが処理されます。

終了したと思ったら割り込みモニタを削除する必要があります。そうでない場合は、表示されている他のアラートに対しても呼び出されます。

removeUIInterruptionMonitor(photosAlertHandler)