- 下载sdk,解压.
-
添加解压后的framework文件到项目里.
Paste_Image.png -
在storyboard里添加一个view控件,并设置class为GADBannerView (例子的尺寸320,44)
Paste_Image.png - 对应的controller代码内容:
import GoogleMobileAds
@IBOutlet weak var bannerView: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
bannerView.adUnitID = "你的广告单元id"
bannerView.rootViewController = self
self.view.addSubview(bannerView)
var request:GADRequest = GADRequest()
request.testDevices = [""]
bannerView.load(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
-
执行
Paste_Image.png
网友评论