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. 分组在re模块中的使用以及使用正则表达式的技巧

    1.split:切割 使用split不会返回被切割的字符 import re ret = re.split("\d+","5as46asf46asf46a") ...

  3. 如何实现Kali linux系统下的U盘启动(小白指导)

    一.准备工作: 声明:这个“操作”并不会影响你原装的系统,真正的即插即用的哦. (1)4GB的U盘<读写速度比较快的> (2)Kali linux镜像文件 (3)软件Universal-U ...

  4. Python基础总结之第四天开始【格式化‘字符串’】(新手可相互督促)

    年薪20万... 字符串格式化: 先看小案例-------: a = 'hello,my name is %s,I like %s.'%('XiaoHong','football') #在字符串中,[ ...

  5. 手撸PHP数据库连接

    最近这个月过得确实有点狼狈....不停地复习,看书..终于到今天为止考完了2科了.能让我好好地写写博客了..前段时间的PHP课设我多学了点东西,在我们一般老师讲的php连接数据库方面做了一些优化.前段 ...

  6. Java 添加、验证PDF 数字签名

    在设置文档内容保护的方法中,除了对文档加密.添加水印外,应用数字签名也是一种有效防伪手段.数字签名的文件比较容易验证,并且具有较高的权威性和可信度.在PDF文档中,有可直接添加或验证数字签名的功能方法 ...

  7. Java学习-内存划分及内存的调用关系

    一.JAVA内存划分 JAVA的内存可以划分为五个部分:堆.栈.方法区.本地方法区和寄存器. 堆(Heap):凡是new出来的东西都在堆中 如: integer = new Integer(2) // ...

  8. Python flask构建微信小程序订餐系统

    第1章 <Python Flask构建微信小程序订餐系统>课程简介 本章内容会带领大家通览整体架构,功能模块,及学习建议.让大家在一个清晰的开发思路下,进行后续的学习.同时领着大家登陆ht ...

  9. Placement_pools on Rados-GW

    The purpose of this test is to map a RadosGw Bucket to a specific Ceph pool. For exemple, if using a ...

  10. Drawable 使用详解

    极力推荐文章:欢迎收藏 Android 干货分享 阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android Drawable 是Android 中图像显示的常用方法. 概念:Drawable ...