Reputation: 53
Whenever I am calling loadAd()
function either from onAppear()
or with a button click, it's giving the error:
Main thread blocked by synchronous property query on not-yet-loaded property (assetProperty_Tracks) for HTTP(S) asset. This could have been a problem if this asset were being read from a slow network.
Main thread blocked by synchronous property query on not-yet-loaded property (NaturalSize) for HTTP(S) asset. This could have been a problem if this asset were being read from a slow network.
Main thread blocked by synchronous property query on not-yet-loaded property (PreferredTransform) for HTTP(S) asset. This could have been a problem if this asset were being read from a slow network.
Main thread blocked by synchronous property query on not-yet-loaded property (EstimatedDataRate) for HTTP(S) asset. This could have been a problem if this asset were being read from a slow network.
Main thread blocked by synchronous property query on not-yet-loaded property (NominalFrameRate) for HTTP(S) asset. This could have been a problem if this asset were being read from a slow network.
Resulting in giving me "Ad wasn't loaded". Here is my loadAd()
:
class AdCoordinator: NSObject, GADFullScreenContentDelegate, ObservableObject {
private var ad: GADRewardedAd?
func loadAd() {
GADRewardedAd.load(
withAdUnitID: "ca-app-pub-3940256099942544/1712485313", request: GADRequest()
) { ad, error in
if let error = error {
return print("Failed to load ad with error: \(error.localizedDescription)")
}
self.ad = ad
self.ad?.fullScreenContentDelegate = self
}
}
func presentAd(from viewController: UIViewController) {
guard let fullScreenAd = ad else {
return print("Ad wasn't ready")
}
fullScreenAd.present(fromRootViewController: viewController, userDidEarnRewardHandler: didEarnedReward) // didEarnedReward prints "reward earned"
}
}
The ad unit ID here is from Google's documentation.
Upvotes: 4
Views: 719