ios-swift版添加admob横幅广告示例

2016-12-16  本文已影响109人  yytester
  1. 下载sdk,解压.
  2. 添加解压后的framework文件到项目里.


    Paste_Image.png
  3. 在storyboard里添加一个view控件,并设置class为GADBannerView (例子的尺寸320,44)


    Paste_Image.png
  4. 对应的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.
    }
  1. 执行


    Paste_Image.png
上一篇下一篇

猜你喜欢

热点阅读