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

  1. 下载sdk,解压.
  2. 添加解压后的framework文件到项目里.


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


    ios-swift版添加admob横幅广告示例_第1张图片
    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. 执行


    ios-swift版添加admob横幅广告示例_第2张图片
    Paste_Image.png

你可能感兴趣的:(ios-swift版添加admob横幅广告示例)