iOS开发 - AdMob广告快速集成

使用CocoaPods 快速集成AdMob广告

官方文档
简单步骤:
打开终端 cd 到你的工程根目录下(手动拖拽进窗口也可)
运行命令pod init,然后他就会生成podfile文件了
常用命令:
ls 查看该目录下的文件
cd .. 返回上级

Simulator Screen Shot 2016年9月4日 下午3.25.12.png

配置podfile文件

    # Uncomment this line to define a global platform for your project
    # platform :ios, '9.0'

    source 'https://github.com/CocoaPods/Specs.git'
    use_frameworks!
    target '你的项目名字' do
    pod 'Google-Mobile-Ads-SDK', '~> 7.0'
    end

终端 pod install 安装


import UIKit
import GoogleMobileAds //导入框架

class ViewController: UIViewController {
      
    @IBOutlet weak var bannerView: GADBannerView! {
        didSet {
            //您自己的广告单元的ID
            bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
            bannerView.rootViewController = self
            
            let request = GADRequest()
            request.testDevices = ["2077ef9a63d2b398840261c8221a0c9a"] //测试设备ID
            self.bannerView.loadRequest(request)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()

    }
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容