在IOS Swift中调用Chartboost的委托方法

时间:2017-10-03 20:48:36

标签: ios swift delegates chartboost

我已将Chartboost集成到我的应用中,我可以看到广告,但我没有牢牢掌握代表,我在使用Chartboost提供的代码时遇到问题导致在广告被查看后发生操作。我的app代理代码如下(我替换了我正在使用的实际appid和签名):

class AppDelegate: UIResponder, UIApplicationDelegate, ChartboostDelegate {

    var window: UIWindow?

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
            application.isStatusBarHidden = true

       Chartboost.start(withAppId: "appID", appSignature: "appSignature", delegate: self)

       Chartboost.cacheRewardedVideo(CBLocationHomeScreen)
       Chartboost.cacheInterstitial(CBLocationHomeScreen)

        func didDisplayInterstitial(_ location: String!){print("didDisplayI")}
        func didCloseInterstitial(_ location: String!){print("didCloseI")}
        func didDismissInterstitial(_ location: String!){print("didDismissI")}

        return true
    }

然后在我的ViewController中,我有以下内容:

class CharacterCreationViewController: UIViewController, ChartboostDelegate {

weak var delegate: ChartboostDelegate?

Override func viewDidLoad() {
        super.viewDidLoad()
        Chartboost.setDelegate(self)
    }

@IBAction func watchAd(_ sender: Any) {

        Chartboost.showInterstitial(CBLocationLevelStart)
        delegate?.didDismissInterstitial!(CBLocationLevelStart)
        delegate?.didCloseInterstitial!(CBLocationLevelStart)
        delegate?.didDisplayInterstitial!(CBLocationLevelStart)

           }

watchAd功能是一个按钮,当我按下它时,广告就会运行,但是一旦广告完成/​​关闭/关闭,appDelegate文件中的所有操作都不会运行。

我搜索了StackOverflow和Chartboost帮助部分并发送了Chartboost支持,但我很难找到我出错的地方。

0 个答案:

没有答案