如何在 Swift 中实施 Chartboost didCloseInterstitial
How to implement Chartboost didCloseInterstitial in Swift
我已经在我的 Swift 应用程序中成功设置了 Chartboost,但我想在间隙视图关闭时的特定时间调用一个函数。
我在 Objective-C 方面的经验几乎为零(可能是问题所在),但由于能够访问 Chartboost class 和整个过程,我显然已经链接了我的 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)
将委托设置为自己,现在可以了。
我已经在我的 Swift 应用程序中成功设置了 Chartboost,但我想在间隙视图关闭时的特定时间调用一个函数。
我在 Objective-C 方面的经验几乎为零(可能是问题所在),但由于能够访问 Chartboost class 和整个过程,我显然已经链接了我的 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)
将委托设置为自己,现在可以了。