0

On my app I used to present programmatically an UIAlert with the following code:

debugPrint("didReceiveInvitationFromPeer")
        
        let fieldAlert = UIAlertController(title: "Richiesta di conssessione",
                                           message: "da parte di \(peerID.displayName)",
            preferredStyle: .alert)
        
        fieldAlert.addAction( UIAlertAction(title: "Rifiuta", style: .cancel) { (action) in
            invitationHandler(false, nil)
        } )
        
        fieldAlert.addAction( UIAlertAction(title: "accetta", style: .default) { (action) in
            invitationHandler(true, self.session)
            
            delay(2) {
                // do stuff
            }
        } )

if let scene = UIApplication.shared.connectedScenes.first,
            let sd : SceneDelegate = (scene.delegate as? SceneDelegate) {
            
            sd.window?.rootViewController?.present(fieldAlert, animated: true, completion: nil)
        }

but now SceneDelegate not exists anymore, is there any solution to how can present the alert?

Raja Kishan
  • 16,767
  • 2
  • 26
  • 52
Damiano Miazzi
  • 1,514
  • 1
  • 16
  • 38
  • If you need to access window, here is possible solution https://stackoverflow.com/a/63276688/12299030. Everything else should work as is. – Asperi Jan 27 '21 at 04:13

1 Answers1

1

No need SceneDelegate, you can directly present by this

UIApplication.shared.windows.first?.rootViewController?.present(fieldAlert, animated: true, completion: nil
Raja Kishan
  • 16,767
  • 2
  • 26
  • 52