TeadsSDK-iOS
TeadsSDK-iOS copied to clipboard
Video ads often not start playing in SwiftUI
I have implemented Teads through SwiftUI.
Some video ads or scroll-to-animate ads are not starting playing most of view presentations if I scroll the list from the bottom.
I mean if the list was loaded with 0 offset and I scroll from the top, videos work well. But if the list was pre-scrolled at some deeper point, and I slowly scroll back to the top, the banner appears, the progress bar is progressing but no video.
If I return bannerView
in one line of code directly in makeUIView(context:)
and do nothing in updateUIView then it works like described.
If I set up the TeadsInReadAdView in the updateUIView(_ uiView:)
it works in similar way, but what's the same is empty video when I scroll from the bottom (as I said, if the list was presented with immediately pre-defined offset deeper than the Teads Ad cell).
Scrolling from the bottom — Empty video Scrolling from the top — Video exists and playing As we see, the Ad UIView is presented successfully, we see the title and the progress bar.
In the attached code below:
The bannerView property which is passed here is coming from the Ads Loader. More often it's passed from cache already pre-loaded, in the provided case I've tested pre-loaded, so the TeadsInReadAdView is available immediately when the SwiftUI view is presented.
I've tried a lot of variations, setting constraints manually or not, with all that layout methods called or no or variations.
It works more stable when I directly return bannerView
in makeUIView(context:)
but in some specific cases no.
@MainActor
struct TeadsBannerView: UIViewRepresentable {
let bannerView: TeadsInReadAdView
func makeUIView(context: Context) -> UIView {
return UIView()
}
func updateUIView(_ uiView: UIView, context: Context) {
uiView.addSubview(bannerView)
bannerView.translatesAutoresizingMaskIntoConstraints = false
NSLayoutConstraint.activate([
bannerView.topAnchor.constraint(equalTo: uiView.topAnchor),
bannerView.bottomAnchor.constraint(equalTo: uiView.bottomAnchor),
bannerView.leadingAnchor.constraint(equalTo: uiView.leadingAnchor),
bannerView.trailingAnchor.constraint(equalTo: uiView.trailingAnchor),
])
bannerView.setNeedsLayout()
bannerView.layoutIfNeeded()
bannerView.layoutSubviews()
}
}
// Another version
@MainActor
struct TeadsBannerView: UIViewRepresentable {
let bannerView: TeadsInReadAdView
func makeUIView(context: Context) -> TeadsInReadAdView {
return bannerView
}
func updateUIView(_ uiView: TeadsInReadAdView, context: Context) { }
}
Have no idea how to solve that, maybe you can take a look and find the right direction? I believe there is some issue in the TeadsInReadAdView life cycle, it is missing some update trigger when it should be triggered.