Thursday, April 16, 2015

iAd for iPhones and iPads

1. Choose "Swift" for language and "Universal" for devices. Set the project name as iad_swift_universal. (Note: If "iphone" is used for the devices option, iAd works with iphones only and iPads will not display iAd.)

2. In "Targets," select iad_swift_universal. At top select the "General" tab. Select "Linked Frameworks and Libraries" and add the iAd framework.

3. Select the storyboard and unselect "Use Auto Layout."

4. Drag an iAd BannerView to the storyboard.

5. Control-drag the ADBannerView to the ViewController. Select "delegate" as the outlet.

6. Complete the code as below:

import UIKit
import iAd

class ViewController: UIViewController, ADBannerViewDelegate {

    override func viewDidLoad() {
        // Do any additional setup after loading the view, typically from a nib.

    func bannerViewDidLoadAd(banner: ADBannerView!) {
    func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
        return true
    func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {


No comments:

Post a Comment