我想在我的函数中删除“'windows'在iOS 15.0中已弃用:在相关窗口场景上使用UIWindowScene.windows”消息(顺便说一下,我的函数运行良好。)。
涉及的代码行:
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
我怎样才能做到这一点?
我的功能:
struct AdView : UIViewRepresentable {
func makeUIView(context: UIViewRepresentableContext<AdView>) -> GADBannerView {
let banner = GADBannerView(adSize: kGADAdSizeBanner)
banner.adUnitID = "ca-app-pub-3940256099942544/2934735716" // test ad
banner.rootViewController = UIApplication.shared.windows.first?.rootViewController
banner.load(GADRequest())
return banner
}
func updateUIView(_ uiView: GADBannerView, context: UIViewRepresentableContext<AdView>) {}
}
我试过了,但它不工作:
banner.rootViewController = UIApplication.shared.connectedScenes.first?.rootViewController
谢谢