iOS development uses Swift to add IAD ads

Source: Internet
Author: User

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 iAdand 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.