ios - Interstitial ad on start of App -
ios - Interstitial ad on start of App -
i'd know how add together interstitial advertisement on start of ios app, written in swift. have searched whole web found answers in objective c (which i'm not able utilize swift) , android.
is there chance (i'd utilize iads) advertising opens in fullscreen when user starts app?
why apple it's available ipad?
i have code used before. written in swift. can utilize in wherever want. first checks iad, if fails show admit banner. may remove admit related parts if don't want.
class adhelper: nsobject { private var iterationstillpresentad = 0 // can used show advertisement after fixed number of iterations private var admobkey = "ca-app-pub-3841570660522725/9161546495" // stores key provided google private var counter = 0 private var admobinterstitial: gadinterstitial! // initialize iad , admob interstitials ads init(presentingviewcontroller: uiviewcontroller, googleadmobkey: string, iterationstillpresentinterstitialad: int) { self.iterationstillpresentad = iterationstillpresentinterstitialad self.admobkey = googleadmobkey self.admobinterstitial = gadinterstitial(adunitid: self.admobkey) presentingviewcontroller.interstitialpresentationpolicy = adinterstitialpresentationpolicy.manual } // nowadays interstitial ads func showads(presentingviewcontroller: uiviewcontroller) { // check if advertisement should shown counter++ if counter >= iterationstillpresentad { // seek if iad advertisement available if presentingviewcontroller.requestinterstitialadpresentation() { counter = 0 presentingviewcontroller.interstitialpresentationpolicy = adinterstitialpresentationpolicy.none // advertisement used. prefetch next 1 preloadiadinterstitial(presentingviewcontroller) // seek if admob available } else { if admobinterstitial == nil { // in case disablead called admobinterstitial = gadinterstitial(adunitid: self.admobkey) } else { // nowadays admob ad, if available if (self.admobinterstitial.isready) { counter = 0 admobinterstitial!.presentfromrootviewcontroller(presentingviewcontroller) admobinterstitial = gadinterstitial(adunitid: self.admobkey) } } // prefetch next ads preloadiadinterstitial(presentingviewcontroller) preloadadmobinterstitial() } } } // disable ads func disablead(presentingviewcontroller: uiviewcontroller) { presentingviewcontroller.interstitialpresentationpolicy = adinterstitialpresentationpolicy.none admobinterstitial = nil } // prefetch admob ads private func preloadadmobinterstitial() { var request = gadrequest() request.testdevices = ["kgadsimulatorid"] // needed show ads in simulator self.admobinterstitial.loadrequest(request) } // prefetch iad ads private func preloadiadinterstitial(presentingviewcontroller: uiviewcontroller) { presentingviewcontroller.interstitialpresentationpolicy = adinterstitialpresentationpolicy.manual uiviewcontroller.prepareinterstitialads() }
}
call function want(possible before view did load in case):
adhelper.showads(self)
ios swift iad
Comments
Post a Comment