美文网首页
ios 谷歌广告

ios 谷歌广告

作者: 飞天蛤蟆 | 来源:发表于2017-12-20 17:29 被阅读0次

    在swift中使用
    1,pod 'Firebase/AdMob',
    2, 导入头文件 #import"Firebase.h",在桥接文件中
    3,HomeViewController.swift中

    class HomeViewController : UIViewController{
        var interstitial : GADInterstitial!
        override func viewDidLoad() {
            super.viewDidLoad()
            self.createAndLoadInterstitial()
        }
        func clickADButton(){
            if self.interstitial == nil {
                self.createAndLoadInterstitial()
            }
            if self.interstitial.isReady {
                dispatch_async(dispatch_get_main_queue(), {
                    self.interstitial.presentFromRootViewController(self)
                })
            }
        }
        //
    func createAndLoadInterstitial() {
            self.interstitial = GADInterstitial(adUnitID: "ca-app-pub-8540695118272502/8273251709")
            self.interstitial.delegate = self
            let request = GADRequest()
            //测试设备号,如果不知道,编译后控制台可以看见真机的设备号
            request.testDevices = [kGADSimulatorID, "设备id"]
            self.interstitial.loadRequest(request)
        }
    }
    
    //MARK: - GADInterstitialDelegate
    extension HomeConnectController : GADInterstitialDelegate{
        func interstitialDidDismissScreen(ad: GADInterstitial) {
            self.createAndLoadInterstitial()
        }
        func interstitialDidFailToPresentScreen(ad: GADInterstitial) {
            self.createAndLoadInterstitial()
        }
    }

    相关文章

      网友评论

          本文标题:ios 谷歌广告

          本文链接:https://www.haomeiwen.com/subject/pwtnwxtx.html