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. C# MATLAB混编(二)

    在上一篇博客中说到按照参考教程操作之后依然有两个问题. 问题1:当我在matlab中输入mbuild -setup后    报错 解:这是因为VS与Matlab存在版本匹配问题,理论上来说vs版本最好 ...

  2. 【Kali】kali linux的安装

    资源准备 制作U盘启动盘 准备kali_Linux的分区 禁用快速启动 安装kali_linux 在这篇Blog中笔者将会讲解如何安装kali_linux,kali可以安装到虚拟机上,但这里笔者强烈建 ...

  3. PHP与ECMAScript_5_常用数组相关函数

    PHP ECMAScript 长度 $length = count($array) length = array.length       增 array_unshift($array, new1,n ...

  4. 通过ping命令了解三层转发流程

    ping命令:因特网包探索器.本文主要通过路由器两端不同网段PC互ping来讲解三层转发流程. 例子:PC-A是如何 ping 通 PC-C 的,有几种情况? 说明:1.在条件1阶段PC-C不会刷新a ...

  5. 电信光猫带路由器(F452)的虚拟服务器端口映射

    现在电信宽带的光猫一般都自带路由器功能,为了方便运营商管理网络用户,电信公司插入了企业局域网,网络用户的光猫路由器都是这个局域网的节点.用户家里的电脑在网络中的结构位置一般如下所示: 互联网(公网)= ...

  6. spring boot中的声明式事务管理及编程式事务管理

    这几天在做一个功能,具体的情况是这样的: 项目中原有的几个功能模块中有数据上报的功能,现在需要在这几个功能模块的上报之后生成一条消息记录,然后入库,在写个接口供前台来拉取消息记录. 看到这个需求,首先 ...

  7. Sring 的 @AliasFor 使用规则

    一.该标签存在的意义 顾名思义 @AliasFor 表示别名,它可以注解到自定义注解的两个属性上,表示这两个互为别名,也就是说这两个属性其实同一个含义.该标签存在的含义,从网上查发现有个点, 若  自 ...

  8. OLE--SWT高级控件

    OLE和ActiveX控件的支持    OLE(Object Link Embeded)是指在程序之间链接和嵌入对象数据.通过OLE技术可以在一个应用程序中执行其他的应用程序.    而ActiveX ...

  9. java并发笔记之四synchronized 锁的膨胀过程(锁的升级过程)深入剖析

    警告⚠️:本文耗时很长,先做好心理准备,建议PC端浏览器浏览效果更佳. 本篇我们讲通过大量实例代码及hotspot源码分析偏向锁(批量重偏向.批量撤销).轻量级锁.重量级锁及锁的膨胀过程(也就是锁的升 ...

  10. 五、Python基础(2)

    五,Python基础(2) 1.数据类型基础 (一)什么是数据类型? 用于区分变量值的不同类型. (二)为何对数据分类? 针对不同状态就应该用不同类型的数据去标识. (三)数据类型分类 1.数字类型 ...