I'm using Xcode 6 + Swift.
Does anybody know how to integrate Google Ads, GoogleMobileAdsSdkiOS on a Swift Project? how to config, and how to program?
I created a new file Teste-Bridging-Header.h
on the project and put #import GADBannerView.h
based on this reference
on my ViewController.swift
some thing like:
class ViewController: UIViewController {
override func viewDidAppear(animated: Bool) {
super.viewWillAppear(animated)
var adB = GADBannerView()
adB.delegate = self
adB.rootViewController = self
adB.adUnitID = MY_ADS_ID //"ca-app-pub-XXXXXXXX/XXXXXXX"
}
}
Am I going in the right direction? Can I get some examples?
now its working...
on .h created Objective-C bridging header I put:
#import "GADBannerView.h"
#import "GADBannerViewDelegate.h"
#import "GADRequest.h"
my swift file:
class ViewController: UIViewController, GADBannerViewDelegate {
override func viewDidAppear(animated: Bool) {
super.viewWillAppear(animated)
var adB = GADBannerView( frame:CGRectMake(0, 0, 320, 50) )
adB.delegate = self
adB.rootViewController = self
adB.adUnitID = "ca-app-pub-XXXXXXX/XXXXXXXX"
var reqAdB = GADRequest()
//reqAdB.testDevices = [ GAD_SIMULATOR_ID ] //not working, dont know why
//reqAdB.testDevices = ["Simulator"] //not working, dont know why
adB.loadRequest(reqAdB)
self.view.addSubview(adB)
}
}
You don't need to do all the Objective-C bridging stuff. I also had this problem and had to search the framework files for clues. I found a comment that included the updated definition name: kDFPSimulatorID
So just change it to this:
Should work.
I managed to get everything compiling and working by using this:
To get it to work, I had to make sure to include "_-Bridging-Header.h" (with your project name) in the "Swift Compiler - Code Generation" section, "Objective-C Bridging Header" field (as original posted suggested).