
1.下载sdk , 解压
2.导入项目文件夹:
3.在info.plist里加入应用id(不是广告单元id): GADApplicationIdentifier
设置Build Settings选项
5.设置appDelegate:
import GoogleMobileAds
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
GADMobileAds.sharedInstance().start(completionHandler: nil)
return true
}
6.设置ViewController:
import UIKit
import GoogleMobileAds
class ViewController: UIViewController,GADBannerViewDelegate {
var bannerView: GADBannerView!
override func viewDidLoad() {
super.viewDidLoad()
bannerView = GADBannerView(adSize: kGADAdSizeBanner)
bannerView.adUnitID = “ca-app-pub-3940256099942544/2934735716”
bannerView.rootViewController = self
bannerView.load(GADRequest())
bannerView.delegate = self
addBannerViewToView(bannerView)
}
func addBannerViewToView(_ bannerView: GADBannerView) {
bannerView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(bannerView)
view.addConstraints(
[NSLayoutConstraint(item: bannerView,
attribute: .bottom,
relatedBy: .equal,
toItem: bottomLayoutGuide,
attribute: .top,
multiplier: 1,
constant: 0),
NSLayoutConstraint(item: bannerView,
attribute: .centerX,
relatedBy: .equal,
toItem: view,
attribute: .centerX,
multiplier: 1,
constant: 0)
])
}
}
相关推荐: 【速卖通3.28】备战大促,卖家该如何调整店铺结构提升订单转换率?
编者按:全球速卖通328周年庆大促是仅次于“双11”的大型促销活动,此次周年庆大促主题叫“狂欢三周年,三天都精彩”,买家端推出了6种玩法,届时海量流量将会给卖家带来单量的显著提升。雨果网近期特推“速卖通3.28”专题,多个维度介绍大促规则、玩法和注意事项,帮助…
码刀科技(www.lekshop.cn)是国内知名企业级电商平台提供商,为企业级商家提供最佳的电商平台搭建(多种模式电商平台搭建:B2B/B2B2C/B2C/O2O/新零售/跨境等)、平台管理系统开发及互联网采购解决方案服务, 联系客服了解更多.