コンテンツにスキップ

Rewarded Ads

このコンテンツはまだ日本語訳がありません。

Loading a Rewarded Ad

To load a rewarded ad, get an instance of a MARewardedAd object that corresponds to your rewarded ad unit and then call its loadAd method. Implement MARewardedAdDelegate so that you are notified when your ad is ready. This also notifies you of other ad-related events.

#import "ExampleViewController.h"
#import <AppLovinSDK/AppLovinSDK.h>
@interface ExampleViewController()<MARewardedAdDelegate>
@property (nonatomic, strong) MARewardedAd *rewardedAd;
@property (nonatomic, assign) NSInteger retryAttempt;
@end
@implementation ExampleViewController
- (void)createRewardedAd
{
self.rewardedAd = [MARewardedAd sharedWithAdUnitIdentifier: @"«ad-unit-ID»"];
self.rewardedAd.delegate = self;
// Load the first ad
[self.rewardedAd loadAd];
}
#pragma mark - MAAdDelegate Protocol
- (void)didLoadAd:(MAAd *)ad
{
// Rewarded ad is ready to show. '[self.rewardedAd isReady]' now returns 'YES'
// Reset retry attempt
self.retryAttempt = 0;
}
- (void)didFailToLoadAdForAdUnitIdentifier:(NSString *)adUnitIdentifier withError:(MAError *)error
{
// Rewarded ad failed to load
// AppLovin recommends that you retry with exponentially higher delays up to a maximum delay (in this case 64 seconds)
self.retryAttempt++;
NSInteger delaySec = pow(2, MIN(6, self.retryAttempt));
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self.rewardedAd loadAd];
});
}
- (void)didDisplayAd:(MAAd *)ad {}
- (void)didClickAd:(MAAd *)ad {}
- (void)didHideAd:(MAAd *)ad
{
// Rewarded ad is hidden. Pre-load the next ad
[self.rewardedAd loadAd];
}
- (void)didFailToDisplayAd:(MAAd *)ad withError:(MAError *)error
{
// Rewarded ad failed to display. AppLovin recommends that you load the next ad.
[self.rewardedAd loadAd];
}
#pragma mark - MARewardedAdDelegate Protocol
- (void)didRewardUserForAd:(MAAd *)ad withReward:(MAReward *)reward
{
// Rewarded ad was displayed and user should receive the reward
}
@end

Showing a Rewarded Ad

To show a rewarded ad, call showAd on the MARewardedAd object you retrieved.

if ( [self.rewardedAd isReady] )
{
[self.rewardedAd showAd];
}

Accessing the Amount and Currency for a Rewarded Ad

To access the reward amount and currency, override the -[MARewardedAdDelegate didRewardUserForAd:withReward:] callback:

- (void)didRewardUserForAd:(MAAd *)ad withReward:(MAReward *)reward
{
NSLog(@"Rewarded user: %d %@", reward.amount, reward.label);
}

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:

  1. Click Add S2S Reward Callback in your Edit Ad Unit page: Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MRec, ☐Native, ☑Rewarded. Add S2S Reward Callback.
  2. Add the Server Side Callback URL, Reward Amount, and Rewarded Currency Name: Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MRec, ☐Native, ☑Rewarded. Hide Callback Settings. Server Side Callback URL form field. Reward Amount form field. Rewarded Currency Name form field. AppLovin Event Key form field.