【发布时间】:2021-12-07 12:59:38
【问题描述】:
我想在我的函数中删除“'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a related window scene instead”消息(顺便说一句,我的函数运行良好。)。
涉及的代码行:
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
谢谢
【问题讨论】:
标签: swiftui admob rootviewcontroller uiwindowscene