1

Swift 4.2, iOS 12.x

Trying to implement AdMob in my app, but not getting very far.

  1. Created an adMob account, looks ok?
  2. Added NSAppTransportSecurity keys to info.plist ok?
  3. Added this code to load an banner add ok.

    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)
    

Extended class to support GADBannerViewDelegate; getting a call back on it which says error, no ad to show. The console in fact reports this.

2018-12-18 11:49:35.468445+0100 DeX[1547:900808] WF: _WebFilterIsActive returning: YES 2018-12-18 11:49:35.468729+0100 DeX[1547:900808] WF: _userSettingsForUser mobile: { filterBlacklist = ( ); filterWhitelist = ( ); noOverridingAllowed = 1; restrictWeb = 1; useContentFilter = 1; useContentFilterOverrides = 0; whitelistEnabled = 0; } 2018-12-18 11:49:35.468821+0100 DeX[1547:900808] WF: Checking if https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html is in contentFilterOverriddenBlackList 2018-12-18 11:49:35.469159+0100 DeX[1547:900808] WF: Checking if https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html is in contentFilterOverriddenWhiteList 2018-12-18 11:49:35.513610+0100 DeX[1547:900808] WF: * WFLSMMap initWithMap: unable to retrieve threshold from map file. 2018-12-18 11:49:35.518259+0100 DeX[1547:900808] WF: WFLSMScoreNormalizedMap category:1 min:0.338760 max:0.663066 scope:0.324306 2018-12-18 11:49:35.518377+0100 DeX[1547:900808] WF: WFLSMScoreNormalizedMap category:2 min:0.336934 max:0.661240 scope:0.324306 2018-12-18 11:49:35.518439+0100 DeX[1547:900808] WF: +[WFJudge defaultJudge] map:/System/Library/PrivateFrameworks/WebContentAnalysis.framework/content_filter_map3 2018-12-18 11:49:35.518559+0100 DeX[1547:900808] WF: Page not worth analyzing [pageContent length]:7 [[self images] count]==0 [[self 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 is not blocked: 'googleads.g.doubleclick.net' is not explicit 2018-12-18 11:49:35.518760+0100 DeX[1547:900808] WF: WebFilterEvaluator:addData: 'googleads.g.doubleclick.net' at https://googleads.g.doubleclick.net/mads/static/sdk/native/sdk-core-v40.html is not blocked * error *** Request Error: No ad to show.

What have I missed out here? Created the account yesterday afternoon, so less than 24 hours past since I did so?

1
  • This line is the culprit bannerUIView.rootViewController = self.view?.window?.rootViewController
    – Arie Pinto
    Commented Dec 18, 2018 at 11:51

3 Answers 3

1

Try setting Limit Ad Tracking (in Settings/Privacy/Advertising) to off.

1
  • 1
    Tried this too. No change. Thanks anyway Alex. Commented Dec 18, 2018 at 14:32
1

Just change you AdUnitID and rootviewcontroller. Following code, I used and its working fine. Can you please try to use this code

       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)
3
  • The rootviewcontroller is correct, the code is within a SKScene. But my adUnitID evidently isn't working and this one is!! Commented Dec 18, 2018 at 14:10
  • This one from google works too ca-app-pub-3940256099942544/2934735716; nothing wrong with my code, something wrong with the adUintID I got issued it seems... or indeed it simply isn't quite cooked yet. Commented Dec 18, 2018 at 14:31
  • Just received a message from Google telling me mID is approved and added an add Unit to my app. This works!! Also changed the request.testDevices to hex code reported in the console, as per some instructions I seem to have missed. Commented Dec 18, 2018 at 18:02
0

Use bannerView.rootViewController = self

1
  • Sorry gaurav, the message is unrelated to this. Commented Dec 18, 2018 at 14:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.