Swift 4.2,iOS 12.x
尝试在我的应用程序中实施AdMob,但进展不远。
添加了此代码以加载横幅并确定。
bannerView = GADBannerView(adSize: GADAdSize(size: CGSize(width: 320, height: 50), flags: 0), origin: CGPoint(x: 0, y: 0))
bannerView.adUnitID = "ca-app-pub-A/B" // changed this code in this post
bannerView.rootViewController = self.view?.window?.rootViewController
bannerView.delegate = self
let request = GADRequest()
request.testDevices = [ kGADSimulatorID ]
bannerView.load(request)
self.view?.window?.rootViewController?.view.addSubview(bannerView)
扩展类以支持GADBannerViewDelegate;接到回覆说错误,没有广告显示。控制台实际上报告了这一点。
2018-12-18 11:49:35.468445 + 0100 DeX [1547:900808] WF: _WebFilterIsActive返回:是2018年12月18日11:49:35.468729 + 0100 DeX [1547:900808] WF:_userSettingsForUser移动电话:{ filterBlacklist =( ); filterWhitelist =( ); noOverridingAllowed = 1; strictWeb = 1; useContentFilter = 1; useContentFilterOverrides = 0; whitelistEnabled = 0; } 2018-12-18 11:49:35.468821 + 0100 DeX [1547:900808] WF:检查是否 https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html 在contentFilterOverriddenBlackList中2018-12-18 11:49:35.469159 + 0100 DeX [1547:900808] WF:检查是否 https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html 在contentFilterOverriddenWhiteList中2018-12-18 11:49:35.513610 + 0100 DeX [1547:900808] WF: * WFLSMMap initWithMap:无法检索 地图文件中的阈值。 2018-12-18 11:49:35.518259 + 0100 DeX [1547:900808] WF:WFLSMScoreNormalizedMap类别:1分钟:0.338760 最多:0.663066范围:0.324306 2018-12-18 11:49:35.518377 + 0100 DeX [1547:900808] WF:WFLSMScoreNormalizedMap类别:2分钟:0.336934 最多:0.661240范围:0.324306 2018-12-18 11:49:35.518439 + 0100 DeX [1547:900808] WF:+ [WFJudge defaultJudge] 映射:/System/Library/PrivateFrameworks/WebContentAnalysis.framework/content_filter_map3 2018-12-18 11:49:35.518559 + 0100 DeX [1547:900808] WF:页面不值 分析[pageContent长度]:7 [[自身图像]计数] == 0 [[自我 scriptBlocks] [count]:2 2018-12-18 11:49:35.518693 + 0100 DeX [1547:900808] WF:WebFilterEvaluator:addData: https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html 没有被阻止:“ googleads.g.doubleclick.net”不明确 2018-12-18 11:49:35.518760 + 0100 DeX [1547:900808] WF: WebFilterEvaluator:addData:'googleads.g.doubleclick.net'在 https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html 没有被阻止 * 错误***请求错误:无广告展示。
我在这里错过了什么?昨天下午创建了帐户,距我这样做还不到24小时?
答案 0 :(得分:1)
只需更改您 AdUnitID 和 rootviewcontroller 。 按照以下代码,我使用了它,并且工作正常。 能否请您尝试使用此代码
let bannerView = GADBannerView.init(adSize: kGADAdSizeBanner)
bannerView.rootViewController = self
bannerView.frame = CGRect.init(x: 0, y: 64, width: UIScreen.main.bounds.size.width, height: 50)
bannerView.adUnitID = "ca-app-pub-2205403669616327/4045941432" // changed this code in this post
bannerView.delegate = self
let request = GADRequest()
request.testDevices = [ kGADSimulatorID ]
bannerView.load(request)
bannerView.layer.borderColor = UIColor.red.cgColor
bannerView.layer.borderWidth = 2.0
self.view.addSubview(bannerView)
答案 1 :(得分:0)
使用bannerView.rootViewController = self
答案 2 :(得分:0)
尝试将“限制广告跟踪”(在“设置” /“隐私” /“广告”中)设置为关闭。