为什么我的 AdMob 横幅广告没有显示在屏幕上?
Why isn't my AdMob banner ad being displayed on the screen?
我正在尝试使用 AdMob 制作横幅广告,但我的屏幕上没有显示任何内容。现在,我只想让广告显示在纯白屏幕的底部。这是我正在使用的代码,但它只显示一个没有广告的空白屏幕。为什么会这样?
var bannerView: GADBannerView!
override func viewDidLoad() {
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView.delegate = self
bannerView.adUnitID = AdMob.bannerid
bannerView.rootViewController = self
addBannerViewToView(bannerView)
bannerView.load(GADRequest())
}
//MARK: - AdMob
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
bannerView.alpha = 0
UIView.animate(withDuration: 1, animations: {
bannerView.alpha = 1
})
}
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: view.safeAreaLayoutGuide,
attribute: .bottom,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 0)
])
}
}
我收到以下消息,但应用程序没有崩溃:
2021-01-01 18:15:58.117046-0600 App[4837:919022] WF: === Starting WebFilter logging for process App
2021-01-01 18:15:58.117101-0600 App[4837:919022] WF: _userSettingsForUser mobile: {
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
2021-01-01 18:15:58.117140-0600 App[4837:919022] WF: _WebFilterIsActive returning: NO
2021-01-01 18:15:58.238219-0600 App[4837:919224] 7.3.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2021-01-01 18:15:58.238983-0600 App[4837:919224] 7.3.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
我需要更改什么?
此问题已解决。我还没有在我的 Admob 账户中输入我的账单信息,所以我的账户验证还没有被处理。如果您遇到同样的问题,我建议:
- 将您的设备注册为测试设备
- 使用 test ad
检查您的代码
如果出现测试广告,请确保您已采取必要措施验证您的帐户。
我正在尝试使用 AdMob 制作横幅广告,但我的屏幕上没有显示任何内容。现在,我只想让广告显示在纯白屏幕的底部。这是我正在使用的代码,但它只显示一个没有广告的空白屏幕。为什么会这样?
var bannerView: GADBannerView!
override func viewDidLoad() {
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView.delegate = self
bannerView.adUnitID = AdMob.bannerid
bannerView.rootViewController = self
addBannerViewToView(bannerView)
bannerView.load(GADRequest())
}
//MARK: - AdMob
func adViewDidReceiveAd(_ bannerView: GADBannerView) {
bannerView.alpha = 0
UIView.animate(withDuration: 1, animations: {
bannerView.alpha = 1
})
}
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: view.safeAreaLayoutGuide,
attribute: .bottom,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 0)
])
}
}
我收到以下消息,但应用程序没有崩溃:
2021-01-01 18:15:58.117046-0600 App[4837:919022] WF: === Starting WebFilter logging for process App
2021-01-01 18:15:58.117101-0600 App[4837:919022] WF: _userSettingsForUser mobile: {
filterBlacklist = (
);
filterWhitelist = (
);
restrictWeb = 1;
useContentFilter = 0;
useContentFilterOverrides = 0;
whitelistEnabled = 0;
}
2021-01-01 18:15:58.117140-0600 App[4837:919022] WF: _WebFilterIsActive returning: NO
2021-01-01 18:15:58.238219-0600 App[4837:919224] 7.3.0 - [Firebase/Analytics][I-ACS023012] Analytics collection enabled
2021-01-01 18:15:58.238983-0600 App[4837:919224] 7.3.0 - [Firebase/Analytics][I-ACS023220] Analytics screen reporting is enabled. Call +[FIRAnalytics logEventWithName:FIREventScreenView parameters:] to log a screen view event. To disable automatic screen reporting, set the flag FirebaseAutomaticScreenReportingEnabled to NO (boolean) in the Info.plist
我需要更改什么?
此问题已解决。我还没有在我的 Admob 账户中输入我的账单信息,所以我的账户验证还没有被处理。如果您遇到同样的问题,我建议:
- 将您的设备注册为测试设备
- 使用 test ad 检查您的代码
如果出现测试广告,请确保您已采取必要措施验证您的帐户。