当我将这个方法放在application(_ application: UIApplication, didFinishLaunchingWithOptions中时
GADMobileAds.configure(withApplicationID: "MYAPPID")
我的广告如期而至。
但是,只要我将GADMobileAds.configure(withApplicationID: "MYAPPID")移动到位于库框架内的助手方法,并调用该助手方法,广告就不会显示出来。据我所知,控制台中没有显示出问题所在的日志。
有人知道为什么会这样吗?
发布于 2017-04-04 13:56:03
Swift 3.0
在中使用此委托
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)
}
}发布于 2017-04-04 17:57:54
来自Google Admob Documentation for iOS的一部分
初始化谷歌移动广告开发工具包
在应用程序启动时,通过在应用程序中调用configureWithApplicationID:初始化Google Mobile Ads SDK :didFinishLaunchingWithOptions: method of AppDelegate.m或AppDelegate.swift。configureWithApplicationID:@"ca-app-pub-3940256099942544~1458002511";-CSwift AppDelegate.m
在应用程序启动时初始化Google Mobile Ads SDK允许SDK获取应用程序级别的设置并尽早执行配置任务。这可以帮助减少初始广告请求的等待时间。初始化需要应用程序ID。应用程序ID是在AdMob console.中注册移动应用程序时为其指定的唯一标识符
所以,IMHO,你必须在应用程序启动时调用这个配置函数。
希望这能有所帮助!
https://stackoverflow.com/questions/43198744
复制相似问题