我已经在我的Swift应用中成功设置了Chartboost,但想在插页式视图关闭时的某些时间调用函数。

我对Objective-C的经验几乎为零(可能是问题),但是由于能够访问Chartboost类和整个过程正常工作,因此我的Obj-C文件显然已链接。

我在几个地方尝试了以下方法,但均未成功:

func didCloseInterstitial(location: CBLocation) {
    print("closing interstitial")
}

func didDismissInterstitial(location: CBLocation) {
    print("dismissing interstitial")
}


这是Obj-C文档:

/*!
 @abstract
 Called after an interstitial has been dismissed.

 @param location The location for the Chartboost impression type.

 @discussion Implement to be notified of when an interstitial has been dismissed for a given CBLocation.
 "Dismissal" is defined as any action that removed the interstitial UI such as a click or close.
 */
- (void)didDismissInterstitial:(CBLocation)location;

/*!
 @abstract
 Called after an interstitial has been closed.

 @param location The location for the Chartboost impression type.

 @discussion Implement to be notified of when an interstitial has been closed for a given CBLocation.
 "Closed" is defined as clicking the close interface for the interstitial.
 */
- (void)didCloseInterstitial:(CBLocation)location;

最佳答案

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

func didDismissInterstitial(_ location: CBLocation) {
    print("dismissing interstitial")
}


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

func didDismissInterstitial(_ location: String) {
    print("dismissing interstitial")
}


我还必须使用Chartboost.setDelegate(self)将委托设置为self,它现在可以工作。

关于ios - 如何在Swift中实现Chartboost didCloseInterstitial,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/45115730/

10-11 14:52