第一步:注册账号
首先你得上admob官网注册账号,得到你的广告单位ID号
如下图:
第二步:下载admob SDK
1.下载地址:http://download.csdn.net/detail/li962429707/8640981
2.导入swift项目:
选择解压好的SDK
在storyboard中添加一块view,并设置好布局:
选择Class
编辑代码:
import UIKit
import GoogleMobileAds
class ViewController: UIViewController {
@IBOutlet weak var bannerView: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
bannerView.adUnitID = "你的广告ID"
bannerView.rootViewController = self
self.view.addSubview(bannerView)
var request:GADRequest = GADRequest()
request.testDevices = [""]
bannerView.loadRequest(request)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
运行情况:
时间: 2024-10-09 06:15:05