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. Java并发-CopyOnWriteArrayList

    前言 今天我们一起学习下java.util.concurrent并发包里的CopyOnWriteArrayList工具类.当有多个线程可能同时遍历.修改某个公共数组时候,如果不希望因使用synchro ...

  2. 以for循环的方式了解var与let的区别

    var是ES5定义变量的一种声明方式. let是ES6定义变量的一种声明方式---可定义局部变量,即定义块级作用域. 以下列简单的函数进行表现二者作用域的不同 在ES6之前,我们都是用var来声明变量 ...

  3. Linux系统安装jdk——.tar.gz版

    1.rpm.deb.tar.gz的区别: rpm格式的软件包适用于基于Red Hat发行版的系统,例如Red Hat Linux.SUSE.Fedora. deb格式的软件包则是适用于基于Debian ...

  4. mysql8.0忘记密码如何操作?

    很不幸,刚安装了MYSQL8,由于密码验证方式的不同,自己折腾了一小会,不小心退出来了,进不去了.从网上面查了一下资料,好多都不是特别好使,最后摸索出来可以进行如下操作: 1. 在配置文件中设置将密码 ...

  5. springboot - 登录+静态资源访问+国际化

    1.项目目录结构 2.pom.xml <?xml version="1.0" encoding="UTF-8"?> <project xmln ...

  6. [P2216] [HAOI2007]理想的正方形 「单调队列」

    思路:用单调队列分别维护行与列. 具体实现方法:是先用单调队列对每一行的值维护,并将a[][]每个区间的最大值,最小值分别存在X[][]和x[][]中. 那么X[][]与x[][]所存储的分别是1×n ...

  7. vue更改了数据但是视图却没有更新

    今日总结:让钩子函数背锅的一上午,跪求原谅 需求:页面刷新时,保留当前页面的选中状态 解决思路:在data里设置一下初始值,保证首次进入有默认选中状态,其次再操作时,把选中的状态存sessionSto ...

  8. 19.包 logging 的使用

    包 什么是包: ---文件夹下具有__init__.py文件就是一个包 推荐使用 from . import 包的导入; from ss.bake.api.policy import func --- ...

  9. interceptor拦截器

    fifter.servlet.interceptor fifter用来处理请求头.请求参数.编码的一些设置,然后转交给servlet,处理业务,返回 servlet现在常用的spring,servle ...

  10. dubbo负载均衡是如何实现的?

    dubbo的负载均衡全部由AbstractLoadBalance的子类来实现 RandomLoadBalance 随机 在一个截面上碰撞的概率高,但调用量越大分布越均匀,而且按概率使用权重后也比较均匀 ...