- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
尝试使用 Native Google Ad documentation 在 UITablewViewCell 中展示 Google 广告。但是,我不断得到
Failed Ad Request: Error Domain=com.google.admob Code=1 "Request Error: No ad to show." UserInfo={NSLocalizedDescription=Request Error: No ad to show.}
这是我的配置:
我需要在表格 View 的第三行显示自定义广告。
GoogleAdBannerView.swift 导入 UIKit 导入 GoogleMobileAds
class GoogleAdBannerView: GADUnifiedNativeAdView {
let modMediaView: GADMediaView = {
let mediaView = GADMediaView()
mediaView.translatesAutoresizingMaskIntoConstraints = false
return mediaView
}()
let bannerImageView: UIImageView = {
let imageview = UIImageView()
imageview.translatesAutoresizingMaskIntoConstraints = false
return imageview
}()
let adTitle: UILabel = {
let label = UILabel()
label.font = UIFont.mySFMedium(ofSize: 16)
label.textColor = UIColor.black.withAlphaComponent(0.87)
label.translatesAutoresizingMaskIntoConstraints = false
return label
}()
let refreshBtn: UIButton = {
let btn = UIButton()
btn.setTitle("Refresh", for: .normal)
btn.setTitleColor(.blue, for: .normal)
btn.layer.cornerRadius = 2
btn.layer.borderWidth = 1
btn.layer.borderColor = UIColor(red:0.85, green:0.85, blue:0.85, alpha:1.0).cgColor
btn.translatesAutoresizingMaskIntoConstraints = false
return btn
}()
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)!
setupViews()
}
override init(frame: CGRect) {
super.init(frame: frame)
setupViews()
}
func setupViews() {
mediaView = modMediaView
iconView = bannerImageView
headlineView = adTitle
addSubview(mediaView!)
addSubview(iconView!)
addSubview(headlineView!)
addSubview(refreshBtn)
mediaView?.widthAnchor.constraint(equalTo: widthAnchor, constant: -32).isActive = true
mediaView?.heightAnchor.constraint(equalToConstant: 160).isActive = true
mediaView?.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
mediaView?.topAnchor.constraint(equalTo: topAnchor, constant: 16).isActive = true
iconView?.widthAnchor.constraint(equalToConstant: 40).isActive = true
iconView?.heightAnchor.constraint(equalToConstant: 40).isActive = true
iconView?.leftAnchor.constraint(equalTo: leftAnchor, constant: 16).isActive = true
iconView?.topAnchor.constraint(equalTo: mediaView!.bottomAnchor, constant: 16).isActive = true
headlineView?.leftAnchor.constraint(equalTo: iconView!.rightAnchor, constant: 16).isActive = true
headlineView?.topAnchor.constraint(equalTo: iconView!.topAnchor).isActive = true
headlineView?.rightAnchor.constraint(equalTo: rightAnchor, constant: -16).isActive = true
refreshBtn.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -16).isActive = true
refreshBtn.heightAnchor.constraint(equalToConstant: 45).isActive = true
refreshBtn.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 2/3, constant: -32).isActive = true
refreshBtn.leftAnchor.constraint(equalTo: leftAnchor, constant: 16).isActive = true
}
}
表格 View 单元格:
FieldListLiteAdCell.swift
import UIKit
import GoogleMobileAds
class FieldListLiteAdCell: UITableViewCell, GADUnifiedNativeAdLoaderDelegate {
let mainView: GoogleAdBannerView = {
let view = GoogleAdBannerView()
view.backgroundColor = .white
view.translatesAutoresizingMaskIntoConstraints = false
return view
}()
var controller: FieldListView? {
didSet {
if let _ = controller {
fetchAds()
}
}
}
var adLoader: GADAdLoader!
override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
super.init(style: style, reuseIdentifier: reuseIdentifier)
self.backgroundColor = UIColor.white
self.selectionStyle = .none
addSubview(mainView)
mainView.widthAnchor.constraint(equalTo: widthAnchor).isActive = true
mainView.heightAnchor.constraint(equalTo: heightAnchor).isActive = true
mainView.centerXAnchor.constraint(equalTo: centerXAnchor).isActive = true
mainView.centerYAnchor.constraint(equalTo: centerYAnchor).isActive = true
mainView.refreshBtn.addTarget(self, action: #selector(refreshFieldAds(_:)), for: .touchUpInside)
fetchAds()
}
@IBAction func refreshFieldAds(_ sender: UIButton) {
fetchAds()
}
private func fetchAds() {
adLoader = GADAdLoader(adUnitID: "ca-app-pub-3940256099942544/3986624511", rootViewController: controller, adTypes: [GADAdLoaderAdType.unifiedNative], options: nil)
adLoader.delegate = self
let adRequest = GADRequest()
adRequest.testDevices = [kGADSimulatorID]
adLoader.load(adRequest)
// adLoader.load(GADRequest())
}
func adLoader(_ adLoader: GADAdLoader, didReceive nativeAd: GADUnifiedNativeAd) {
mainView.nativeAd = nativeAd
nativeAd.delegate = self
print("Ad has been received.")
mainView.mediaView?.mediaContent = nativeAd.mediaContent
(mainView.iconView as? UIImageView)?.image = nativeAd.icon?.image
(mainView.headlineView as? UILabel)?.text = nativeAd.headline
}
func adLoaderDidFinishLoading(_ adLoader: GADAdLoader) {
}
func adLoader(_ adLoader: GADAdLoader, didFailToReceiveAdWithError error: GADRequestError) {
print("Failed Ad Request: ", error)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
// MARK: - GADUnifiedNativeAdDelegate implementation
extension FieldListLiteAdCell: GADUnifiedNativeAdDelegate {
func nativeAdDidRecordClick(_ nativeAd: GADUnifiedNativeAd) {
print("\(#function) called")
}
func nativeAdDidRecordImpression(_ nativeAd: GADUnifiedNativeAd) {
print("\(#function) called")
}
func nativeAdWillPresentScreen(_ nativeAd: GADUnifiedNativeAd) {
print("\(#function) called")
}
func nativeAdWillDismissScreen(_ nativeAd: GADUnifiedNativeAd) {
print("\(#function) called")
}
func nativeAdDidDismissScreen(_ nativeAd: GADUnifiedNativeAd) {
print("\(#function) called")
}
func nativeAdWillLeaveApplication(_ nativeAd: GADUnifiedNativeAd) {
print("\(#function) called")
}
}
我不知道我做错了什么。根据一些 StackOverflow 答案的建议,尝试了多个应用单元 ID,创建了多个帐户,等待了 2 小时以上。确保设备 ID 添加到请求中。
编辑 1
有人将该问题标记为可能重复,并提出了未经验证的建议。我必须制作一个示例应用程序来实现相同的逻辑,并且它工作正常。
我已检查了 Info.plist
文件,以确保允许任意加载
设置为 YES
。我尚未确定错误背后的原因。
Sample GoogleAd Native Implementation
如有任何帮助,我们将不胜感激。谢谢。
最佳答案
显然,我没有做错任何事。
注释掉在应用委托(delegate)中初始化应用时进行的应用范围 UserAgent
修改,可以使 Google Ad Mod
正常工作。
我的UserAgent
看起来像这样:
用户代理:iOS-公司名称/版本号
。
我不知道为什么我的自定义用户代理会阻止我获取广告
。
关于iOS 原生 AdMob,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55322880/
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 1年前关闭。 Improve thi
当我在 Admob 页面中创建插页式广告单元时,它要求输入 Interstitial timeout : Determine how long to display the interstitial
关闭。这个问题不满足Stack Overflow guidelines .它目前不接受答案。 想改善这个问题吗?更新问题,使其成为 on-topic对于堆栈溢出。 2年前关闭。 Improve thi
我的应用使用奖励视频广告,但在我看来,有时广告太长了。如何设置广告的时长限制? 最佳答案 这不是 AdMob 提供的功能。不过,感觉太长的广告通常会获得较少的点击次数,因此随着系统的调整,展示次数会越
我正在使用 admob 插页式广告,它通过 onCreate 加载 所以我可以使用它一次,但不能使用两次。我必须重新加载它然后使用它... 我想在显示后立即重新加载它,但似乎没有这样的回调监听器...
我有 admob 帐户,并且广告单元已成功放入我的应用程序中。 现在我想在我的应用程序中打印 admob 报告,就像用户 ABC 在这个应用程序中点击了“_”次赚取和应用程序的 RPM 我该怎么做,有
这可能是题外话,但请这对我们所有人都非常有帮助,他们从未知来源获得虚假点击,只是为了暂停我们的 admob 帐户。 最佳答案 对于 iOS 您应该使用 here 所述的委托(delegate)方法计算
Admob 几天前迁移到了较新的版本。他们成功转移了我的应用程序,但似乎我必须从 0,00 美元重新开始。我的旧 Admob 大约有 15 美元。我怎样才能把它转移到新的,否则它会丢失吗?支付限额为
我认为有人试图让我在 AdMob 中被禁止 - 在来自“未知”国家/地区的地理统计点击中,点击率达到 80%-90%(其他国家/地区 < 3%)。 如果用户来自“未知”国家/地区,是否有办法阻止展示广
我在展示来自 admob 的广告时在布局上遇到了一些问题。 应用刚启动时没有广告,一切正常。布局占据整个屏幕。然后当应用程序可以加载广告时(在顶部),整个布局将向下移动以显示广告。 如果有广告时整个布
是否可以在 Android 上以多种语言显示 GDPR 同意对话框? 我只能用一种语言发布一条消息。 在ump sdk中没有看到拟合方法。 我的意思是必须有办法做到这一点,如果没有,那么这个 sdk
我在 iOS 游戏中使用 AdMob,我最近更新了它以在我的 Info.plist 文件中包含 AdMob SKAdNetworkIdentifier(因为我的 AdMob 帐户中有警告要求这样做)。
这是我的代码: gAdView=[[GADBannerView alloc] initWithFrame:CGRectMake(0,self.view.bounds.size.height-GAD_S
Google 对使用 是否有限制或警告?奖励广告 限时? 因此,在我的应用程序中,如果我让我的用户按他/她想要的次数观看激励广告,将 谷歌 将其视为 无效流量这会导致帐户停用? 最佳答案 不,激励广告
我在 Google Play 上发布了一个游戏,我在上面放了 admob 广告。 由于无效的点击事件,我的 admob 帐户被禁用。 现在我创建了另一个帐户,将我的游戏链接到它。 我显示广告的代码是正
关于 AdSense 报告 API - GET/accounts/accountId/reports 它是仅检索 AdMob 数据(作为广告网络)还是也可以包括来自其他中介广告网络的数据? 最佳答案
我已经知道这个问题的答案,但我之所以这么问,是因为我花了几个小时才找到它,并且想让其他人轻松获得它。 自 2020 年 12 月 8 日起,Apple 已强制要求开发人员发布正在收集的数据以及这些数据
使用 AdWhirl 我得到了这些异常(exception)... 我无法从我这边发现错误...... 任何人都可以对此提出建议.. FATAL EXCEPTION: main E/AndroidRu
这就是我的 Admob 横幅的实现方式。 在 Layout.xml 中 在 AdActivity.java 中 private void initBannerViewGroup()
我想在同一事件中同时展示横幅广告和插页式广告。但我不确定这是否会违反 Google admob 政策,因为当显示插页式广告时,它会覆盖横幅广告。 谢谢。 最佳答案 这是允许的。事实上,建议您这样做以增
我是一名优秀的程序员,十分优秀!