如何在没有 SceneDelegate 的情况下使用 SwiftUI 2 更新我的应用程序代码
How can I update my app code using SwiftUI 2 where there is no SceneDelegate
在我的应用程序中,我曾经使用以下代码以编程方式呈现 UIAlert:
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)
}
但是现在SceneDelegate已经不存在了,请问有什么办法可以提示alert吗?
不需要SceneDelegate,直接用这个就可以呈现
UIApplication.shared.windows.first?.rootViewController?.present(fieldAlert, animated: true, completion: nil
在我的应用程序中,我曾经使用以下代码以编程方式呈现 UIAlert:
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)
}
但是现在SceneDelegate已经不存在了,请问有什么办法可以提示alert吗?
不需要SceneDelegate,直接用这个就可以呈现
UIApplication.shared.windows.first?.rootViewController?.present(fieldAlert, animated: true, completion: nil