所需:当代理方法调用成功时,我想做些事情观察:代理方法未成功调用屏幕上的广告节目
错误
代码:Chartboost.delegate =自我

错误:类型“ Chartboost”没有成员“代表”

AppDelegate

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool  {

    Chartboost.start(withAppId: "4f21c409cd1cb2fb7000001b", appSignature: "92e2de2fd7070327bdeb54c15a5295309c6fcd2d", delegate: nil)

    return true
}


ViewController代码

class ViewController: UIViewController,GADBannerViewDelegate, GADInterstitialDelegate,GADRewardBasedVideoAdDelegate,IMBannerDelegate, IMInterstitialDelegate ,ChartboostDelegate{

    @IBAction func Vedio(_ sender: Any) {

        Chartboost.showRewardedVideo(CBLocationMainMenu)

    }

    @IBAction func LoadFullAd(_ sender: Any) {

        Chartboost.showInterstitial(CBLocationHomeScreen)
    }

     private func shouldDisplayRewardedVideo(_ location: CBLocation) -> Bool {
        return true
    }

    private func shouldRequestInterstitial(_ location: CBLocation) -> Bool {
        return true
    }

}

最佳答案

必须使用Chartboost.setDelegate(self)将委托设置为self

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

    Chartboost.start(withAppId: "4f21c409cd1cb2fb7000001b", appSignature: "92e2de2fd7070327bdeb54c15a5295309c6fcd2d", delegate:self as ChartboostDelegate)
    Chartboost.setDelegate(self as ChartboostDelegate)

    return true
}


在研究了如何在Swift中正确转换Objective-C方法之后,我添加了下划线(_),将函数更改为:

func shouldDisplayRewardedVideo(_ location: CBLocation) -> Bool
{

    return true
}
 func shouldRequestInterstitial(_ location: CBLocation) -> Bool {

    return true
}


然后,XCode提示我接近委托方法,但是需要更改位置类型,最后我得到了

func shouldDisplayRewardedVideo(_ location: String) -> Bool
{

    return true
}
 func shouldRequestInterstitial(_ location: String) -> Bool {

    return true
}

关于ios - Chartboost代表无法快速运行,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/49547734/

10-10 20:52