Rewarded Ads
このコンテンツはまだ日本語訳がありません。
Loading a Rewarded Ad
The following code shows you how to bind to delegates and load the first rewarded ad:
// UMyWidget.cpp (UMyWidget inherits from UObject to access TimerManager)
#include "UMyWidget.h"#include "AppLovinMAX.h"
// For retry timer logic#include "Async/Async.h"#include "Engine/World.h"#include "TimerManager.h"
const FString RewardedAdUnitId = TEXT("«ad-unit-ID»");int RetryAttempt = 0;FTimerHandle LoadTimerHandle;
void UMyWidget::InitializeRewardedAds(){ // Bind member functions to delegates UAppLovinMAX::OnRewardedAdLoadedDelegate.AddUObject(this, &UMyWidget::OnRewardedAdLoaded); UAppLovinMAX::OnRewardedAdLoadFailedDelegate.AddUObject(this, &UMyWidget::OnRewardedAdLoadFailed); UAppLovinMAX::OnRewardedAdDisplayFailedDelegate.AddUObject(this, &MyWidget::OnRewardedAdDisplayFailed); UAppLovinMAX::OnRewardedAdHiddenDelegate.AddUObject(this, &UMyWidget::OnRewardedAdHidden); UAppLovinMAX::OnRewardedAdReceivedRewardDelegate.AddUObject(this, &UMyWidget::OnRewardedAdReceivedReward);
// Load first rewarded ad LoadRewardedAd();}
void UMyWidget::LoadRewardedAd(){ UAppLovinMAX::LoadRewardedAd(RewardedAdUnitId);}
void UMyWidget::OnRewardedAdLoaded(const FAdInfo &AdInfo){ // Rewarded ad is ready to be shown. UAppLovinMAX::IsRewardedAdReady(RewardedAdUnitId) will now return 'true'
// Reset retry attempt RetryAttempt = 0;}
void UMyWidget::OnRewardedAdLoadFailed(const FAdInfo &AdInfo, const FAdError &AdError){ // Rewarded ad failed to load // AppLovin recommends that you retry with exponentially higher delays, up to a maximum delay (in this case 64 seconds)
RetryAttempt++;
AsyncTask(ENamedThreads::GameThread, [this]() { float RetryDelay = FMath::Pow(2.0f, FMath::Min(6, RetryAttempt)); GetWorld()->GetTimerManager().SetTimer(LoadTimerHandle, this, &UMyWidget::LoadRewardedAd, RetryDelay, false); });}
void UMyWidget::OnRewardedAdDisplayFailed(const FAdInfo &AdInfo, const FAdError &AdError){ // Rewarded ad failed to display. AppLovin recommends that you load the next ad. LoadRewardedAd();}
void UMyWidget::OnRewardedAdHidden(const FAdInfo &AdInfo){ // Rewarded ad is hidden. Pre-load the next ad. LoadRewardedAd();}
void UMyWidget::OnRewardedAdReceivedReward(const FAdInfo &AdInfo, const FAdReward &Reward){ // Rewarded ad was displayed and user should receive the reward}
Showing a Rewarded Ad
To show a rewarded ad, call ShowRewardedAd()
:
if (UAppLovinMAX::IsRewardedAdReady(RewardedAdUnitId)){ UAppLovinMAX::ShowRewardedAd(RewardedAdUnitId);}
S2S Rewarded Callbacks
You can receive callbacks to your currency server. To learn how, see the MAX S2S Rewarded Callback API guide. Then update the Server Side Callback URL in your Edit Ad Unit page.
Setting the Amount and Currency for a Rewarded Ad
To set the reward amount and currency:
- Click Add S2S Reward Callback in your Edit Ad Unit page:
- Add the Server Side Callback URL, Reward Amount, and Rewarded Currency Name: