跳转到内容

激励广告

加载激励广告

要加载激励广告,请创建与您的激励广告单元对应的 MARewardedAd 实例对象,然后调用其 loadAd 方法。 实现 MARewardedAdDelegate 以便在广告准备就绪时收到通知。这也会通知您其他广告相关的事件。

#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

展示激励广告

要展示激励广告,请调用您获取的 MARewardedAd 对象的 showAd 方法。

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

获取激励广告的金额和币种

要获取奖励金额和币种,请重写 -[MARewardedAdDelegate didRewardUserForAd:withReward:] 回传:

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

S2S 激励回传

您可以通过货币服务器接收回传。 要了解操作方法,请参阅 MAX S2S Rewarded Callback API 指南。 随后,在Edit Ad Unit页面更新Server Side Callback URL

设置激励广告的金额和币种

要设置激励广告的金额和币种,请按照下列步骤操作:

  1. Edit Ad Unit 页面点击Add S2S Reward Callback:Ad Type: ☐App Open, ☐Banner, ☐Interstitial, ☐MRec, ☐Native, ☑Rewarded.Add S2S Reward Callback.
  2. 添加 Server Side Callback URLReward AmountRewarded 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.