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;
  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.reward
  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!)")
}

<광고 참여 상태를 확인하는데 필요한 API>

API

설명

totalReward

해당 광고에 할당된 총 리워드 양을 나타냅니다.

리워드 적립 주기가 지나지 않아 광고에 리워드가 할당되지 않는 경우에는 0으로 내려오게 됩니다.

availableReward

해당 광고에 남아있는 총 리워드 양을 나타냅니다.

유저가 광고에서 특정 액션을 취하지 않아 받아가지 못한 리워드가 있을때 0보다 큰 값을 갖게됩니다.

isParticipated

현재 할당 받은 광고들의 참여 상태를 sync하기 위한 값입니다.

광고 참여가 일어나면 해당 광고 및 메모리 상의 동일 광고들의 isParticipated값이 true로 바뀌며 onParticipate 콜백이 호출됩니다.

isClicked

현재 할당 받은 광고의 클릭 여부를 나타내기 위한 값입니다.

광고를 클릭한 적이 있으면 true로 변경됩니다. 일부 액션형 광고의 경우 서버에서 참여 여부를 실시간으로 판단할 수 없습니다. 이 경우에는 isParticipated 값이 true가 아니므로, Click이 발생한 경우 “참여 확인 중” 이라는 CTA로 변경하여 유저 혼선을 줄일 수 있습니다.

isActionType

참여형 광고의 경우 True 이며, 노출형 광고의 경우 False 입니다.

한번에 여러 개의 광고 로드

WithSize를 설정하여 loadAds를 호출하면, 한 번의 광고 요청으로 여러 개의 광고를 할당받을 수 있습니다. 캐로셀형태와 같은 지면을 구현하는 경우 사용할 수 있습니다. 최대 10개까지 가능합니다.

...