When I put this method in application(_ application: UIApplication, didFinishLaunchingWithOptions
GADMobileAds.configure(withApplicationID: "MYAPPID")
My ads show up as expected.
However, as soon as I move the GADMobileAds.configure(withApplicationID: "MYAPPID")
to a helper method located inside a library framework, and call that helper method instead, the ads do not show up. And there is no log in the console that indicates what's wrong as far as I can tell.
Does anyone know why this is the case?
Swift 3.0
Use this delegates in
class ViewController: UIViewController , GADBannerViewDelegate{
// put this line in viewdidload()
let bannerview1 : GADBannerView = GADBannerView(frame: CGRect(x: 0, y: 0, width: self.view.frame.size.width, height: 50))
bannerview1.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerview1.rootViewController = self
bannerview1.delegate = self
bannerview1.load(GADRequest())
self.view.addSubview(bannerview1)
// Delegates for adv error
func adView(_ bannerView: GADBannerView, didFailToReceiveAdWithError error: GADRequestError) {
print(error)
}
}
A part from Google Admob Documentation for iOS :
Initialize the Google Mobile Ads SDK
At app launch, initialize the Google Mobile Ads SDK by calling configureWithApplicationID: in the application:didFinishLaunchingWithOptions: method of AppDelegate.m or AppDelegate.swift. Objective-CSwift AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { // Use Firebase library to configure APIs [FIRApp configure]; [GADMobileAds configureWithApplicationID:@"ca-app-pub-3940256099942544~1458002511"]; return YES; }
Initializing the Google Mobile Ads SDK at app launch allows the SDK to fetch app-level settings and perform configuration tasks as early as possible. This can help reduce latency for the initial ad request. Initialization requires an app ID. App IDs are unique identifiers given to mobile apps when they're registered in the AdMob console.
So, IMHO, you must have to call this configure function on application launch.
Hope that helps!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.