我有几个问题让我感到困惑:
bannerView.load(GADRequest()) 后,让开发人员或 Google 监控它是最佳做法吗? viewControllerA 中,但用户按下按钮并按下 viewControllerB。由于 viewControllerA 仍在堆栈中,广告将不断刷新,因此在 viewControllerA 被释放之前,我不知道 Google 如何知道屏幕已关闭。另外,如果用户进入后台,Google 怎么知道?我假设 关闭 意味着用户无法再看到屏幕,这意味着他们无法看到广告,因此无需刷新,因为他们要么切换了标签页,推送了另一个 VC,要么转到了后台(所有情况下)在下面的代码中处理)
Refreshing ads
We recommend that you have ads persist for 60 seconds or longer, depending on the functionality of your app. Our internal tests have shown that this ensures users have enough time to engage with ads, providing the best performance for both advertisers and publishers. Furthermore, these tests have shown that refreshing ads more often can hurt fill rate for our publishers.
If your app is automatically refreshing ads, make sure ad requests are not made when the screen is off. Also, if users navigate to and from pages with ads in an app over a short period of time, a new ad request should not be made sooner than the recommended 60 second rate.
Banner ads
We recommend using the Google-optimized automatic refresh rate. The optimized rate is calculated using AdMob historical data to ensure the ads shown in your ad units are being refreshed at the best rate for banner ads.
You may also set a custom refresh rate of 30-120 seconds or disable refresh rate completely.
var timer: Timer?
override viewDidLoad() {
super.viewDidLoad()
// instantiate bannerView ...
NotificationCenter.default.addObserver(self, selector: #selector(startAdRefreshTimer), name: UIApplication.willEnterForegroundNotification, object: nil)
// *** the screen is OFF
NotificationCenter.default.addObserver(self, selector: #selector(stopAdRefreshTimer), name: UIApplication.willResignActiveNotification, object: nil)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
startAdRefreshTimer()
}
// *** the screen is OFF
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
stopAdRefreshTimer()
}
@objc func startAdRefreshTimer() {
timer?.invalidate()
timer = Timer.scheduledTimer(withTimeInterval: 30,
repeats: true,
block: { [weak self](timer) in
self?.refreshAd()
})
}
func refreshAd() {
bannerView.load(GADRequest())
}
@objc func stopAdRefreshTimer() {
if timer != nil {
timer?.invalidate()
timer = nil
}
}
// this really isn't necessary because of what's in viewWillDisappear but I added it anyway
@objc func buttonToPushNextVCTapped() {
let nextVC = NextVC()
navigationController?.pushViewController(viewController: nextVC, animated: true, completion: { [weak self] in
// *** the screen is OFF
self?.stopAdRefreshTimer()
})
}
最佳答案
回答我的第一、第二和第三个问题:
第一个这是我的 setup, I have the bannerView inside a headerView 似乎是 totally fine 。我也在使用 TabBarController 。顺便说一句, collectionView 所在的 vc 处理 bannerView 和 load(GADRequest()) 。 headerView 只显示广告,所以我不必担心它会随着用户滚动和 headerView 被回收而不断被调用。您可以阅读我的设置中的链接以获取更多详细信息。
第二个 AdMob 的 BannerView 有一个 delegate method,它在收到新广告时被调用:
MyController: GADBannerViewDelegate {
/// Tells the delegate an ad request loaded an ad.
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
print("adViewDidReceiveAd")
}
}
load(GADRequest()) 并在它准备好时更改广告。每 60 年代更换一次广告对我来说很好。如果场景可以吸引用户的注意力超过一分钟,那就是转换了 2 个广告。这更有益,因为我可以花更多时间来吸引他们的注意力,而不是专注于为他们提供广告。bannerView.load(GADRequest()) 以转换新闻广告 load(GADRequest())) 广告,当屏幕为 关闭 时,不需要浪费时间担心它 

关于ios - AdMob 刷新请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57412813/
在我的Controller中,我通过以下方式在我的index方法中支持HTML和JSON:respond_todo|format|format.htmlformat.json{renderjson:@user}end在浏览器中拉起它时,它会自然地以HTML呈现。但是,当我对/user资源进行内容类型为application/json的curl调用时(因为它是索引方法),我仍然将HTML作为响应。如何获取JSON作为响应?我还需要说明什么? 最佳答案 您应该将.json附加到请求的url,提供的格式在routes.rb的路径中定义。这
这里有一个很好的答案解释了如何在Ruby中下载文件而不将其加载到内存中:https://stackoverflow.com/a/29743394/4852737require'open-uri'download=open('http://example.com/image.png')IO.copy_stream(download,'~/image.png')我如何验证下载文件的IO.copy_stream调用是否真的成功——这意味着下载的文件与我打算下载的文件完全相同,而不是下载一半的损坏文件?documentation说IO.copy_stream返回它复制的字节数,但是当我还没有下
我正在尝试解析一个文本文件,该文件每行包含可变数量的单词和数字,如下所示:foo4.500bar3.001.33foobar如何读取由空格而不是换行符分隔的文件?有什么方法可以设置File("file.txt").foreach方法以使用空格而不是换行符作为分隔符? 最佳答案 接受的答案将slurp文件,这可能是大文本文件的问题。更好的解决方案是IO.foreach.它是惯用的,将按字符流式传输文件:File.foreach(filename,""){|string|putsstring}包含“thisisanexample”结果的
rails中是否有任何规定允许站点的所有AJAXPOST请求在没有authenticity_token的情况下通过?我有一个调用Controller方法的JqueryPOSTajax调用,但我没有在其中放置任何真实性代码,但调用成功。我的ApplicationController确实有'request_forgery_protection'并且我已经改变了config.action_controller.consider_all_requests_local在我的environments/development.rb中为false我还搜索了我的代码以确保我没有重载ajaxSend来发送
目录1.AdmobSDK下载地址2.将下载好的unityPackagesdk导入到unity里编辑 3.解析依赖到项目中
1.错误信息:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:requestcanceledwhilewaitingforconnection(Client.Timeoutexceededwhileawaitingheaders)或者:Errorresponsefromdaemon:Gethttps://registry-1.docker.io/v2/:net/http:TLShandshaketimeout2.报错原因:docker使用的镜像网址默认为国外,下载容易超时,需要修改成国内镜像地址(首先阿里
print"Enteryourpassword:"pass=STDIN.noecho(&:gets)puts"Yourpasswordis#{pass}!"输出:Enteryourpassword:input.rb:2:in`':undefinedmethod`noecho'for#>(NoMethodError) 最佳答案 一开始require'io/console'后来的Ruby1.9.3 关于ruby-为什么不能使用类IO的实例方法noecho?,我们在StackOverflow上
我是Ruby的新手。我试过查看在线文档,但没有找到任何有效的方法。我想在以下HTTP请求botget_response()和get()中包含一个用户代理。有人可以指出我正确的方向吗?#PreliminarycheckthatProggitisupcheck=Net::HTTP.get_response(URI.parse(proggit_url))ifcheck.code!="200"puts"ErrorcontactingProggit"returnend#Attempttogetthejsonresponse=Net::HTTP.get(URI.parse(proggit_url)
在我的路线文件中我有:match'graphs/(:id(/:action))'=>'graphs#(:action)'如果是GET请求(工作)或POST请求(不工作),我想匹配它我知道我可以使用以下方法在资源中声明POST请求:post'/'=>:show,:on=>:member但是我怎样才能为比赛做到这一点呢?谢谢。 最佳答案 如果你同时想要POST和GETmatch'graphs/(:id(/:action))'=>'graphs#(:action)',:via=>[:get,:post]编辑默认值可以设置如下match'g
我试图像这样在我的测试用例中执行获取:request.env['CONTENT_TYPE']='application/json'get:index,:application_name=>"Heka"虽然,它失败了:ActionView::MissingTemplate:Missingtemplatealarm_events/indexwith{:handlers=>[:builder,:haml,:erb,:rjs,:rhtml,:rxml],:locale=>[:en,:en],:formats=>[:html]尽管在我的Controller中我有:respond_to:html,