func updateCtaButton(ad: BABAd) {
let callToAction = ad.creative.callToAction ?? "디폴트 스트링"
let reward = ad.rewardgetAvailableReward()
let totalReward = ad.getTotalReward()
let isParticipated = ad.isParticipated()
let isClicked = ad.isClicked()
let isActionType = ad.isActionType()
if (isClicked && isActionType && !isParticipated) {
rewardIcon.image = nil
ctaLabel.text = "참여 확인 중"
// LayoutConstraint 조정
...
} else {
if (totalReward > 0 && isParticipated) {
rewardIcon.image = UIImage(named: "ic_check")
ctaLabel.text = "참여 완료"
// LayoutConstraint 조정
...
} else if (reward > 0) {
rewardIcon.image = UIImage(named: "ic_coin")
ctaLabel.text = "\(Int(ad.reward))P \(callToAction)"
// LayoutConstraint 조정
...
} else {
rewardIcon.image = nil
ctaLabel.text = callToAction
// LayoutConstraint 조정
...
}
}
}
// MARK: BABNativeAdViewDelegate
// 광고가 impress 되었을 때 호출됩니다.
func babNativeAdView(_ adView: BABNativeAdView, didImpress ad: BABAd) {
NSLog("Integration QA: ad impressed")
}
// 광고가 click 되었을 때 호출됩니다.
func babNativeAdView(_ adView: BABNativeAdView, didClick ad: BABAd) {
self.updateCtaButton(ad: ad);
NSLog("Integration QA: ad clicked")
}
// 리워드 요청이 시작될 때 호출됩니다.
func babNativeAdView(_ adView: BABNativeAdView, willRequestRewardFor ad: BABAd) {
self.updateCtaButton(ad: ad);
NSLog("Integration QA: will request reward for ad \(ad.creative.title!)")
}
// 리워드 요청이 완료되었을 때 호출됩니다. 결과는 `result` 인자에 담겨있습니다.
func babNativeAdView(_ adView: BABNativeAdView, didRewardFor ad: BABAd, with result: BABRewardResult) {
NSLog("Integration QA: reward request result \(result)")
}
// 광고에 참여 완료 되었을 때 호출됩니다. 이곳에서 UI를 참여 완료 상태로 변경합니다.
func babNativeAdView(_ adView: BABNativeAdView, didParticipateAd ad: BABAd) {
self.updateCtaButton(ad: ad);
// self.rewardIcon.image = UIImage(named: "ic_check")
NSLog("Integration QA: ad participated \(ad.creative.title!)")
} |