0

Today I registered to adMob and I started working on adMob ads inside my apps.The first one is a game (with viewcontrollers) and i want to show an interstitial ad right after the game over screen, so i want to load the interstitial right after the view with game over loads (this view is accessible only after game over and a game lasts for one minute so it should not appear too often)

I have seen many tutorials, on youtube and on admob website, i had many problems like: admob framework not found even if I imported it, i disabled bitcode to avoid linker errors when i build, but i still can't see the test ad on my app, on the simulator and real devices.

I imported all the frameworks required by admob, and in xcode i have a question mark near GoogleMobileAds framework, what does it mean? First line about admob is:

import GoogleMobileAds

inside viewcontroller

var interstitial: GADInterstitial!
func createNloadAd () -> GADInterstitial
{
    var ad = GADInterstitial(adUnitID: "XXX")



    var request = GADRequest()

    request.testDevices = [kGADSimulatorID]

    ad!.loadRequest(request)

    return ad

}

inside viewdidload

self.interstitial = self.createNloadAd()
    if(self.interstitial!.isReady)
    {
        self.interstitial!.presentFromRootViewController(self)
        self.interstitial! = self.createNloadAd()
    }

in adUnitID I tried the ID of the interstitial i created in admob website, and other strings found inside tutorials, but none worked

in testdevices i added my iphone's UDID after i see the message in output, but i can't see any test ad and i have no error at all

And i didn't touch the storyboard,do I have to create something in the storyboard?

Before submitting the app to appstore i have to remove the testdevices line?And of course put my real AdUnitID

Maybe the code is right but if the app is not published admob won't load, or maybe I have to wait a day before my admob id starts working

Where I can find recent admob IDs for testing? So i test the app, and if works i change the id and submit

I am using Xcode 7.1, AdMob 7.5.2, and my app deployment target is iOS7 and i tested it on simulator with 9.1 and my old iPhone4 with iOS7, and this should not be a problem because admob supports even iOS6

Another question about admob guidelines, in other apps can i use iAd in a view and Admob in an other?May i be banned for this?only banner ads in lower part of the screen

Wain
  • 118,658
  • 15
  • 128
  • 151
GioB
  • 973
  • 3
  • 11
  • 17

1 Answers1

9

AdMob framework not found even if I imported it

Remove the framework and import it again. Make sure you're checking "Copy items if needed". Also, check your library search paths under your project settings and build phases to see if the framework is include.

I imported all the frameworks required by AdMob

This is not necessary. The AdMob framework will import the frameworks it needs once you include import GoogleMobileAds.

And I didn't touch the storyboard. Do I have to create something in the storyboard?

No

Before submitting the app to App Store I have to remove the test devices line and put my real AdUnitID?

Yes. Try using your real AdUnitID now to see if your test ID is causing the problem.

Maybe the code is right but if the app is not published AdMob won't load, or maybe I have to wait a day before my AdMob id starts working

No. The application does not have to be published to receive live advertisements.

Where I can find recent AdMob IDs for testing? So I test the app, and if works I change the id and submit

Nowhere. It is not wise to give out your AdUnitID.

Another question about AdMob guidelines, in other apps can I use iAd in a view and AdMob in an other? May I be banned for this? Only banner ads in lower part of the screen

Use as many ad networks in your application as you'd like. There's nothing stating you aren't allowed to.


Sounds like you're on the right track. You should set and include the interstitial's delegate methods though to see if you're getting any error messages. You need to allow arbitrary loads in your .plist too. Check AdMob's iOS 9 Considerations.

Are you calling createNloadAd() before you attempt to present the interstitial in your viewDidLoad? It takes time to download the advertisement.

Make sure the AdUnitID provided by AdMob is identical to the one you're using.

Also, move the presentation from viewDidLoad to viewDidAppear.

Here's an example of creating our interstitial in our AppDelegate.swift and then presenting the interstitial in our ViewController.swift:

AppDelegate.swift

import UIKit
import GoogleMobileAds // Import AdMob

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, GADInterstitialDelegate { // Include delegate

    var window: UIWindow?
    var myInterstitial : GADInterstitial?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        // App launched
        // Load interstitial
        myInterstitial = createAndLoadInterstitial()
        return true
    }

    func createAndLoadInterstitial()->GADInterstitial {
        let interstitial = GADInterstitial(adUnitID: "Your Ad Unit ID")
        interstitial.delegate = self
        interstitial?.loadRequest(GADRequest())
        return interstitial
    }

    func interstitialDidReceiveAd(ad: GADInterstitial!) {
        print("interstitialDidReceiveAd")
    }

    func interstitial(ad: GADInterstitial!, didFailToReceiveAdWithError error: GADRequestError!) {
        print(error.localizedDescription)
    }

    func interstitialDidDismissScreen(ad: GADInterstitial!) {
        print("interstitialDidDismissScreen")
        myInterstitial = createAndLoadInterstitial()
    }

ViewController.swift (This would be your game over view controller)

import UIKit

class ViewController: UIViewController {

    let appDelegate = UIApplication.sharedApplication().delegate as! AppDelegate // Create reference to our app delegate

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
        appDelegate.myInterstitial?.presentFromRootViewController(self)
    }
Daniel Storm
  • 18,301
  • 9
  • 84
  • 152