- 下载sdk , 解压
- 导入项目文件夹:
- 在info.plist里加入应用id(不是广告单元id):
GADApplicationIdentifier
- 设置Build Settings选项
- 设置appDelegate:
import GoogleMobileAds<br>
<br>
<br>
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {<br>
// Override point for customization after application launch.<br>
<br>
GADMobileAds.sharedInstance().start(completionHandler: nil)<br>
<br>
<br>
return true<br>
}<br>
```<br>
6. 设置ViewController:<br>
```<br>
import UIKit<br>
import GoogleMobileAds<br>
<br>
<br>
class ViewController: UIViewController,GADBannerViewDelegate {<br>
var bannerView: GADBannerView!<br>
<br>
override func viewDidLoad() {<br>
super.viewDidLoad()<br>
<br>
bannerView = GADBannerView(adSize: kGADAdSizeBanner)<br>
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"<br>
bannerView.rootViewController = self<br>
bannerView.load(GADRequest())<br>
<br>
bannerView.delegate = self<br>
<br>
addBannerViewToView(bannerView)<br>
<br>
<br>
}<br>
<br>
func addBannerViewToView(_ bannerView: GADBannerView) {<br>
bannerView.translatesAutoresizingMaskIntoConstraints = false<br>
view.addSubview(bannerView)<br>
view.addConstraints(<br>
[NSLayoutConstraint(item: bannerView,<br>
attribute: .bottom,<br>
relatedBy: .equal,<br>
toItem: bottomLayoutGuide,<br>
attribute: .top,<br>
multiplier: 1,<br>
constant: 0),<br>
NSLayoutConstraint(item: bannerView,<br>
attribute: .centerX,<br>
relatedBy: .equal,<br>
toItem: view,<br>
attribute: .centerX,<br>
multiplier: 1,<br>
constant: 0)<br>
])<br>
}<br>
<br>
<br>
}<br>
<br>
<br>
```<br>
<br>
<br>
<br>
<br>
---<br>
<br>
<br>
<br>
参考: [开始使用 | iOS | Google Developers](https://developers.google.com/admob/ios/quick-start#update_your_infoplist)