嗨,我正在开发一个使用滚动视图的基于内容的 iOS 应用程序。我尝试添加测试横幅和插页式 admob 广告并使用 CocoaPods,我添加了横幅和插页式测试广告,但只显示横幅测试广告,插页式广告是根本没有显示。这是代码
class ViewController: UIViewController,UIScrollViewDelegate {
var player:AVAudioPlayer?
@IBOutlet weak var bannerView: GADBannerView!
@IBOutlet var scrollView: UIScrollView!
@IBOutlet var pageControl: UIPageControl!
var interstitial: GADInterstitial!
@IBOutlet var musicButton: UIButton!
@IBOutlet var wallButton: UIButton!
@IBOutlet var shareButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
bannerView.adUnitID = "ca-app-pub-3940256099942544/2934735716"
bannerView.rootViewController = self
bannerView.load(GADRequest())
self.scrollView.frame = CGRect(x: 0, y: 0, width: self.view.frame.width, height: self.view.frame.height)
let scrollViewWidth : CGFloat = self.scrollView.frame.width
let scrollViewHeight :CGFloat = self.scrollView.frame.height
let imgOne = UIImageView(frame: CGRect(x:0, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgOne.image = UIImage(named: "b1")
createAndLoadInterstitial()
let imgTwo = UIImageView(frame: CGRect(x:scrollViewWidth, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgTwo.image = UIImage(named: "b2")
let imgThree = UIImageView(frame: CGRect(x:scrollViewWidth*2, y:0,width:scrollViewWidth, height:scrollViewHeight))//*2 means the position of the scrollview
imgThree.image = UIImage(named: "b3")
let imgFour = UIImageView(frame: CGRect(x:scrollViewWidth*3, y:0,width:scrollViewWidth, height:scrollViewHeight))
imgFour.image = UIImage(named: "b4")
self.scrollView.addSubview(imgOne)
self.scrollView.addSubview(imgTwo)
self.scrollView.addSubview(imgThree)
self.scrollView.addSubview(imgFour)
文件私有函数 createAndLoadInterstitial(){
interstitial = GADInterstitial(adUnitID:"ca-app-pub-3940256099942544/4411468910")
let request = GADRequest()
request.testDevices = [ kGADSimulatorID ]
interstitial.load(request)
}
func alertView(_alertView: UIScrollView,willDismissWithButtonIndex buttonIndex:Int){
if interstitial.isReady{
interstitial.present(fromRootViewController: self)
} else {
print("Ad wasn't ready")
}
}