This is my first time trying to add AdMob to my iOS App and I have installed AdMobs using Swift Package Manager as CocoPods was not working for me. I have done what was mentioned on the Google site for the setup. I have used the following code to set up a banner ad. It works well with the Test ID. But doesn’t work with the real ID that I should use for my app. I’m getting the following error every time I try to run the app on the simulator and my physical device.
I’m using the following code for the banner ad :
import SwiftUI
import GoogleMobileAds
import UIKit
struct GADBannerViewController: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> some UIViewController {
let view = GADBannerView(adSize: GADAdSizeBanner)
let viewController = UIViewController()
let testID = "ca-app-pub-3940256099942544/2934735716"
let realID = "realID"
// Banner Ad
view.adUnitID = realID
view.rootViewController = viewController
// View Controller
viewController.view.addSubview(view)
viewController.view.frame = CGRect(origin: .zero, size: GADAdSizeBanner.size)
// Load an ad
view.load(GADRequest())
return viewController
}
func updateUIViewController(_ uiViewController: UIViewControllerType, context: Context) {}
}
I call the banner ad using the following line:
GADBannerViewController().frame(width: 320, height: 50, alignment: .center)
Anyway to resolve this issue?