Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Expand
titleObjective-C
Code Block
languageobjective-c
- (void)updateCtaButtonWithAd:(BABAd *)ad {
  NSString *callToAction = ad.creative.callToAction;
  double reward = [ad.reward getAvailableReward];
  double totalReward = [ad getTotalReward];
  BOOL isParticipated = [ad isParticipated];
  BOOL isClicked = [ad isClicked];
  BOOL isActionType = [ad isActionType];
  if (isClicked && isActionType && !isParticipated) {
    _rewardIcon.image = nil;
    _ctaLabel.text = @"참여 확인 중";
    
    // LayoutConstraint 조정
    ...
  } else {
    if (totalReward > 0 && isParticipated) {
      _rewardIcon.image = [UIImage imageNamed:@"ic_check"];
      _ctaLabel.text = @"참여 완료";

      // LayoutConstraint 조정
      ...
    } else if (reward > 0) {
      _rewardIcon.image = [UIImage imageNamed:@"ic_coin"];
      _ctaLabel.text = [NSString stringWithFormat:@"+%d %@", (int)reward, callToAction];
      
      // LayoutConstraint 조정
      ...
    } else {
      _rewardIcon.image = nil;
      _ctaLabel.text = callToAction;
      
      // LayoutConstraint 조정
      ...
    }
  }
}

#pragma mark - BABNativeAdViewDelegate
// 광고가 impress 되었을 때 호출됩니다.
- (void)BABNativeAdView:(BABNativeAdView *)adView didImpressAd:(BABAd *)ad {
}

// 광고가 click 되었을 때 호출됩니다.
- (void)BABNativeAdView:(BABNativeAdView *)adView didClickAd:(BABAd *)ad {
  [self updateCtaButtonWithAd:ad];
}

// 리워드 요청이 시작될 때 호출됩니다.
- (void)BABNativeAdView:(BABNativeAdView *)adView willRequestRewardForAd:(BABAd *)ad {
  [self updateCtaButtonWithAd:ad];
}

// 리워드 요청이 완료되었을 때 호출됩니다. 결과는 `result` 인자에 담겨있습니다.
- (void)BABNativeAdView:(BABNativeAdView *)adView didRewardForAd:(BABAd *)ad withResult:(BABRewardResult)result {
}

// 광고에 참여 완료 되었을 때 호출됩니다. 이곳에서 UI를 참여 완료 상태로 변경합니다.
- (void)BABNativeAdView:(BABNativeAdView *)adView didParticipateAd:(BABAd *)ad {
  [self updateCtaButtonWithAd:ad];
}
Expand
titleSwift
Code Block
languageswift
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!)")
}

...