我是新手,在我的移动应用中添加广告,我开始使用Google教程向我的iOS应用添加admob。我已按照他们的说明操作,但在构建应用时遇到了错误。我想在我的应用上为所有用户显示一个插页式广告。我正在使用Google admob的发布商ID。这是我的代码:
// ViewController.swift
// Tic Tac Toe
// Created by Benjamin Emdon on 2015-05-20.
// Copyright (c) 2015 Ben Emdon.
import UIKit
import GoogleMobileAds
class ViewController: UIViewController {
@IBOutlet weak var bannerView: GADBannerView!
@IBOutlet var singleplayerButton: DesignableButton!
@IBOutlet var multiplayerButton: DesignableButton!
override func viewDidLoad() {
super.viewDidLoad()
self.bannerView.adUnitID = "ca-app-pub-6066036695047095/8503439166"
self.bannerView.rootViewController = self
let request: GADRequest = GADRequest()
self.bannerView.loadRequest(request.testDevices = ["9dbd8b758950edd3a2ca208ce50bcca3"])
}
override func viewWillAppear(animated: Bool) {
singleplayerButton.animation = "slideRight"
singleplayerButton.animate()
multiplayerButton.animation = "slideLeft"
multiplayerButton.animate()
}
}
我在testDevice号所在的行收到错误。这是给出的错误:无法将类型'()'的值转换为预期的参数类型'GADRequest!'
答案 0 :(得分:0)
尝试将代码更改为:
let request: GADRequest = GADRequest()
request.testDevices = ["9dbd8b758950edd3a2ca208ce50bcca3"]
self.bannerView.loadRequest(request)
您正在函数调用中进行赋值,您应该执行此操作,然后只需在
中传递请求对象