使用Swift在Spritekit游戏中实现iAd

时间:2015-03-03 02:07:51

标签: swift sprite-kit iad

我似乎无法在SpriteKit游戏中的Swift应用程序中加载iAd横幅...已经谷歌了一段时间而没有任何东西....它只是赢得了网络打电话加载广告...我已经实施了所有必要的电话,并设置了代表没有运气......

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    println("Failed to load ad")

}

func bannerViewDidLoadAd(banner: ADBannerView!) {
    println("Loaded Ad")

    //now show the ad
    //set position off-screen
    banner.frame.origin.y = screenHeight

    banner.hidden = false



}

func createAds() {


    //create ad to allow it to load
    let adBanner = ADBannerView(frame: CGRectMake(0, 0, screenWidth, 50))
    adBanner.delegate = self
    adBanner.center = CGPointMake(screenWidth/2, 25)
    adBanner.hidden = true


    //add to screen
    self.view?.addSubview(adBanner)


    println("Created Ad")


}


func hideAds() {


}

func bannerViewActionShouldBegin(banner: ADBannerView!, willLeaveApplication willLeave: Bool) -> Bool {
    return true
}

然后我只是在游戏开始时调用createAds()方法,然后在屏幕顶部显示一个白色矩形(" 0,0","引用,引用,是吗?零归零"?)

1 个答案:

答案 0 :(得分:0)

你需要这样做(在GameViewController.swift中):

override func viewDidLoad() {
super.viewDidLoad()

self.canDisplayBannerAds = true
}

func bannerViewActionShouldBegin(banner: ADBannerView!,    willLeaveApplication willLeave: Bool) -> Bool {
    return true
}

func bannerViewDidLoadAd(banner: ADBannerView!) {
}

func bannerView(banner: ADBannerView!, didFailToReceiveAdWithError error: NSError!) {
    NSLog("error!")
}

func bannerViewWillLoadAd(banner: ADBannerView!) {
}

您还需要导入iAd 并将ADBannerViewDelegate添加到GameViewController类