1. 下载sdk , 解压
  2. 导入项目文件夹:

     
  3. 在info.plist里加入应用id(不是广告单元id): GADApplicationIdentifier

  4. 设置Build Settings选项

  5. 设置appDelegate:

    <br> import GoogleMobileAds<br> <br> <br> &nbsp; &nbsp; func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {<br> &nbsp; &nbsp; &nbsp; &nbsp; // Override point for customization after application launch.<br> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; GADMobileAds.sharedInstance().start(completionHandler: nil)<br> <br> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp; return true<br> &nbsp; &nbsp; }<br>
  6. 设置ViewController:

    <br> import UIKit<br> import GoogleMobileAds<br> <br> <br> class ViewController: UIViewController,GADBannerViewDelegate {<br> &nbsp; &nbsp; var bannerView: GADBannerView!<br> &nbsp; &nbsp;&nbsp;<br> &nbsp; &nbsp; override func viewDidLoad() {<br> &nbsp; &nbsp; &nbsp; &nbsp; super.viewDidLoad()<br> <br> &nbsp; &nbsp; &nbsp; &nbsp; bannerView = GADBannerView(adSize: kGADAdSizeBanner)<br> &nbsp; &nbsp; &nbsp; &nbsp; bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"<br> &nbsp; &nbsp; &nbsp; &nbsp; bannerView.rootViewController = self<br> &nbsp; &nbsp; &nbsp; &nbsp; bannerView.load(GADRequest())<br> <br> &nbsp; &nbsp; &nbsp; &nbsp; bannerView.delegate = self<br> <br> &nbsp; &nbsp; &nbsp; &nbsp; addBannerViewToView(bannerView)<br> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br> &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br> &nbsp; &nbsp; }<br> &nbsp; &nbsp;&nbsp;<br> &nbsp; &nbsp; func addBannerViewToView(_ bannerView: GADBannerView) {<br> &nbsp; &nbsp; &nbsp; &nbsp; bannerView.translatesAutoresizingMaskIntoConstraints = false<br> &nbsp; &nbsp; &nbsp; &nbsp; view.addSubview(bannerView)<br> &nbsp; &nbsp; &nbsp; &nbsp; view.addConstraints(<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; [NSLayoutConstraint(item: bannerView,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attribute: .bottom,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; relatedBy: .equal,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toItem: bottomLayoutGuide,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attribute: .top,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; multiplier: 1,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; constant: 0),<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NSLayoutConstraint(item: bannerView,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attribute: .centerX,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; relatedBy: .equal,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; toItem: view,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; attribute: .centerX,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; multiplier: 1,<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; constant: 0)<br> &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ])<br> &nbsp; &nbsp; }<br> <br> <br> }<br> <br> <br>









    ---







    参考: 开始使用  |  iOS  |  Google Developers

2019-在iOS里添加admob横幅广告示例的更多相关文章

  1. Unity3D IOS IPhone添加Admob的方法

    原地址:http://dong2008hong.blog.163.com/blog/static/4696882720140403119293/ 首先阅读官方文档https://developers. ...

  2. foreach循环时动态往数组里添加数据

    今天在用TP做项目的时候遇到一个问题,foreach的时候需要动态往数组里添加数据,示例代码如下: $arr = array( array('id'=>'字符串1','name'=>'字符 ...

  3. ios 向工程里添加Fonts

    ios 向工程里添加Fonts 1.网上搜索字体文件(后缀名为.ttf,或.odf),假如你加入的字体为微软雅黑 2.把字体库导入到工程的resouce中 3.然后在你的工程的Info.plist文件 ...

  4. iOS 向模拟器里添加照片

    iOS 向模拟器里添加照片 模拟器里Photos最开始时是没有照片的,有时我们做Demo时需要Photos里面的照片做测试,这时就需要把Mac上的照片导入到模拟器里.步骤如下: 1,打开模拟器 2,选 ...

  5. iOS 在类别里添加成员变量的方法:objc_setAssociatedObject

    今天在github上查看MJPopupViewController这个项目,发现里面用到了objc_setAssociatedObject,用来为类别添加成员变量. 我百度之后,发现有人是这样说明的: ...

  6. visual studio 2019工具里添加开发中命令提示符的方法

    最新新装了visual studio 2019,发现默认的没有开发者命令提示符 现将添加步骤描述如下: 从VS2019菜单选择"Tools",然后选择"外部工具" ...

  7. ionic添加admob广告教程

    1.在你的ionic项目中使用如下命令添加admob插件: cordova plugin add cordova-plugin-admobpro 2.添加完成后,在$ionicPlatform.rea ...

  8. php从数据库里取出的数据列表里添加一个属性实战例子

    php从数据库里取出的数据列表里添加一个属性实战例子:$opendata = $this->omitmodel->getHistory(1,1);var_dump($opendata);f ...

  9. 在Qt Creator 和在 vs2012 里添加信号和槽

    原文地址:http://www.cnblogs.com/li-peng/p/3644812.html 作者:李鹏 出处:http://www.cnblogs.com/li-peng/ 本文版权归作者和 ...

随机推荐

  1. 个人永久性免费-Excel催化剂功能第75波-标签式报表转标准数据源

    数据处理永远是数据分析工作中重中之重的任务,大部分人深深地陷入在数据处理的泥潭中,今天Excel催化剂再接再厉,在过往已提供了主从结构报表数据源的数据转换后,再次给大家送上标签式报表数据源的数据转换操 ...

  2. Python3安装与使用urllib2包之小坑

    Python3 安装urllib2包之小坑 Python3.6.6或者说python3.x找不到urllib2语法问题修改之后,会报一个没有安装urllib2的包的错误. 通过pip install ...

  3. 《VR入门系列教程》之18---Oculus代码剖析

    代码剖析 原文作者:Tony Parisi     那么,Unity究竟是如何支持Oculus VR运行的?首先,我们来看看Unity场景是如何构建的.在Unity集成开发包中有一个相机预设体,这个预 ...

  4. 头部姿态估计 - OpenCV/Dlib/Ceres

    基本思想 通过Dlib获得当前人脸的特征点,然后通过旋转平移标准模型的特征点进行拟合,计算标准模型求得的特征点与Dlib获得的特征点之间的差,使用Ceres不断迭代优化,最终得到最佳的旋转和平移参数. ...

  5. Redis项目实战---应用及理论(上)---redis基础知识介绍

    redis(Remote Dictionary Server)   一.原理及特性层面:     1.优势:        1)数据加载在内存中,执行速度快, 数据结构类似于HashMap,HashM ...

  6. css常用知识与用法

    1 类选择器就是再 某一个标签后面加上class  =“”     然后再到前面去定义这个class   一定要记住前面加. 2 id选择器和类选择器是差不多的   不过id选择器前面不加.而加#   ...

  7. On The Way—Step 1 :python入门之Python的历程

    1.python的历史 2004 Django框架 python2 和 python3的区别 python2 源码不统一 有重复功能代码 python3 源码统一 没有重复功能代码 Python的发展 ...

  8. vue 初始化table数据,数据闪现的问题

    使用的iview,很简单的一个table,可以扩展显示,我这里则是更改了一下,显示的也是表格,内容为明细数据. 原以为很简单的可以直接调用方法,进行数据的渲染,但是没想到,数据只是一闪而过. 百思不得 ...

  9. 并发栅栏CyclicBarrier---简单问2

    并发栅栏CyclicBarrier---简单问 背景:前几天在网上看到关于Java并发包java.concurrent中一个连环炮的面试题,整理下以备不时之需. CyclicBarrier简介: 栅栏 ...

  10. 创建软RAID5

    一  创建4块硬盘组软  RAID5  新增四块20G的新硬盘,将四块硬盘分别分区,全部大小都分为一个区,并改  id  为 “ fd ”      1创建阵列mdadm -Cv /dev/md5 - ...