The first step is to drag a iad bannerview control into the storyboard and the layout is OK.
The second step is to refer the control to the Viewcontroller
The fourth step, the Code section.
Import Uikitimport Iadclass Viewcontroller:Uiviewcontroller, Adbannerviewdelegate {@IBOutletWeakvar myad:adbannerview! Override Func Viewdidload () {Super. Viewdidload()additional setup after loading the view, typically from a nib. Self. Candisplaybannerads=true Self. Myad. Delegate= Self Self. Myad. Hidden=true} override func didreceivememorywarning () {Super. didreceivememorywarning()//Dispose of any resources, can be recreated.} func Bannerviewwillloadad (banner:adbannerview!) {NSLog("Bannerviewwillloadad")} func Bannerviewdidloadad (banner:adbannerview!) {NSLog("Bannerviewdidloadad") Self. Myad. Hidden=false //now Show Banner as AD is loaded} func bannerviewactiondidfinish (banner:adbannerview!) {NSLog("Bannerviewdidloadad")//optional Resume paused game code} func Bannerviewactionshouldbegin (banner:adbannerview!, Willleaveapplication willleave:bool), Bool {NSLog("Bannerviewactionshouldbegin")//optional Pause Game Code return true} func Bannerview (banner:adbannerview!, didfailtoreceiveadwitherror error:Nserror!) {NSLog("Bannerview") }//... your class implementation code}
Note: Requires
import iAd
and interface
ADBannerViewDelegate
Will not be displayed immediately after the operation, and your current network status, there may be a period of time, wish success!
This is what should happen after success.
iOS development uses Swift to add IAD ads