迅捷的Revmob插页式广告

时间:2015-01-13 15:31:42

标签: ios swift xcode6 advertisement revmob

我按照实施Revmob指南为我的游戏使用插页式广告,但是当我启动游戏时出现错误:

2015-01-13 15:02:20.406 basisTest[38021:42032052] [RevMob] Starting RevMobAds
2015-01-13 15:02:21.057 basisTest[38021:42032052] [RevMob] Warning: RevMob session was not started
fatal error: unexpectedly found nil while unwrapping an Optional value

错误指向我的appdelegate中的这一行:

func applicationDidBecomeActive(application: UIApplication) {
    RevMobAds.session().showFullscreen();
}

我的GameViewController中的viewdidload方法:

override func viewDidLoad() {
    super.viewDidLoad()
    let completionBlock: () -> Void = {
        // do something when it successfully starts the session
    }
    let errorBlock: (NSError!) -> Void = {error in
        // check the error
        println(error);
    }
    RevMobAds.startSessionWithAppID("54b515b6b1abae000f771a71",
        withSuccessHandler: completionBlock, andFailHandler: errorBlock);
}

我完全按照指南将所有框架添加到我的项目中,并按预期更改了我的构建设置。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

添加RevMobAds.session().showFullScreen()以使completionBlock代替您的app delegate

override func viewDidLoad() {
super.viewDidLoad()
let completionBlock: () -> Void = {
    // do something when it successfully starts the session
    RevMobAds.session().showFullScreen()
}
let errorBlock: (NSError!) -> Void = {error in
    // check the error
    println(error);
}
RevMobAds.startSessionWithAppID("54b515b6b1abae000f771a71",
    withSuccessHandler: completionBlock, andFailHandler: errorBlock);
}

另外说你想在转换场景时添加它。将整个块放在游戏场景转换位置。

我这样做是因为我不希望广告在应用程序打开时打开,而是在玩家输掉游戏并切换场景时