Two-stage reward advertising: In rewarded video scenarios, through conversion tasks, by doubling or inflating the original reward, extra rewards are used to stimulate users to further convert.
- SDK version >= v6.4.94
- (CocoaPods integration) AnyThinkMediationBaiduAdapter >= 10.032.1
- For manual integration, please visit the SDK download center to re-select and download the Baidu Union SDK version 10.032.1 and its Adapter
- Baidu ad source must be of Rewarded Video type
#import <AnyThinkSDK/AnyThinkSDK.h>
Add the two-stage reward parameters when loading rewarded video ads to enable this feature.
//
// RewardedVC.m
// iOSDemo
//
#import "RewardedVC.h"
#import <AnyThinkSDK/AnyThinkSDK.h>
#import "AdLoadConfigTool.h"
@interface RewardedVC () <ATRewardedVideoDelegate>
@property (nonatomic, assign) NSInteger retryAttempt;
@end
@implementation RewardedVC
// Placement ID
#define RewardedPlacementID @"b67f4ab93eb3a7"
// Scene ID (optional, can be generated in dashboard. Use empty string if none)
#define RewardedSceneID @""
#pragma mark - Load Ad
/// Load advertisement
- (void)loadAd {
NSMutableDictionary *loadConfigDict = [NSMutableDictionary dictionary];
// ============ Two-Stage Reward Configuration Start ============
// Reward type: 1 corresponds to inflated reward, 2 corresponds to multiplied reward
[loadConfigDict setValue:@"1" forKey:kATBaiduRewardedVideoRewardType];
// Inflated reward amount
[loadConfigDict setValue:@"100" forKey:kATBaiduRewardedVideoBasicReward];
// Inflated reward unit (e.g., Yuan, Coin, Diamond, etc.)
[loadConfigDict setValue:@"Yuan" forKey:kATBaiduRewardedVideoBasicUnit];
// Multiplied reward amount
[loadConfigDict setValue:@"200" forKey:kATBaiduRewardedVideoAdvancedReward];
// Multiplied reward unit
[loadConfigDict setValue:@"Yuan" forKey:kATBaiduRewardedVideoAdvancedUnit];
// Multiple for reward, recommended 2x or above
[loadConfigDict setValue:@"2" forKey:kATBaiduRewardedVideoMultiple];
// ============ Two-Stage Reward Configuration End ============
// Server-side reward verification parameters (optional)
[loadConfigDict setValue:@"media_val_RewardedVC" forKey:kATAdLoadingExtraMediaExtraKey];
[loadConfigDict setValue:@"rv_test_user_id" forKey:kATAdLoadingExtraUserIDKey];
[loadConfigDict setValue:@"reward_Name" forKey:kATAdLoadingExtraRewardNameKey];
[loadConfigDict setValue:@3 forKey:kATAdLoadingExtraRewardAmountKey];
// Load ad
[[ATAdManager sharedManager] loadADWithPlacementID:RewardedPlacementID extra:loadConfigDict delegate:self];
}
#pragma mark - Show Ad
/// Display advertisement
- (void)showAd {
// Scene statistics (optional)
[[ATAdManager sharedManager] entryRewardedVideoScenarioWithPlacementID:RewardedPlacementID scene:RewardedSceneID];
// Check if ad is ready
if (![[ATAdManager sharedManager] rewardedVideoReadyForPlacementID:RewardedPlacementID]) {
[self loadAd];
return;
}
// Show configuration
ATShowConfig *config = [[ATShowConfig alloc] initWithScene:RewardedSceneID showCustomExt:@"testShowCustomExt"];
// Show ad
[[ATAdManager sharedManager] showRewardedVideoWithPlacementID:RewardedPlacementID config:config inViewController:self delegate:self];
}
#pragma mark - ATAdLoadingDelegate
/// Ad loading success callback
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
NSLog(@"Ad loaded successfully: %@", placementID);
// Reset retry attempts
self.retryAttempt = 0;
}
/// Ad loading failure callback
- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
NSLog(@"Ad loading failed: %@ Error code: %ld", placementID, error.code);
// Stop retrying after 3 attempts
if (self.retryAttempt >= 3) {
return;
}
self.retryAttempt++;
// Calculate delay time: power of 2, maximum 8 seconds
NSInteger delaySec = pow(2, MIN(3, self.retryAttempt));
// Delayed retry loading
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self loadAd];
});
}
#pragma mark - ATRewardedVideoDelegate
/// Reward success callback (Important: Get reward type)
- (void)rewardedVideoDidRewardSuccessForPlacemenID:(NSString *)placementID extra:(NSDictionary *)extra {
NSLog(@"Reward success: %@ Extra info: %@", placementID, extra);
// Get reward type from extra dictionary
NSString *rewardType = extra[@"reward_type"];
if ([rewardType isEqualToString:@"1"]) {
// User received inflated reward
NSLog(@"User received inflated reward");
// Grant inflated reward to user here
} else if ([rewardType isEqualToString:@"2"]) {
// User received multiplied reward
NSLog(@"User received multiplied reward");
// Grant multiplied reward to user here
}
}
/// Rewarded video started playing
- (void)rewardedVideoDidStartPlayingForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
NSLog(@"Rewarded video started playing: %@", placementID);
}
/// Rewarded video finished playing
- (void)rewardedVideoDidEndPlayingForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {
NSLog(@"Rewarded video finished playing: %@", placementID);
}
/// Rewarded video playback failed
- (void)rewardedVideoDidFailToPlayForPlacementID:(NSString*)placementID error:(NSError *)error extra:(NSDictionary *)extra {
NSLog(@"Rewarded video playback failed: %@ Error code: %ld", placementID, (long)error.code);
// Preload next ad
[self loadAd];
}
/// Rewarded video closed
- (void)rewardedVideoDidCloseForPlacementID:(NSString *)placementID rewarded:(BOOL)rewarded extra:(NSDictionary *)extra {
NSLog(@"Rewarded video closed: %@, Is rewarded: %@", placementID, rewarded ? @"Yes" : @"No");
// Preload next ad
[self loadAd];
}
/// Rewarded video clicked
- (void)rewardedVideoDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {
NSLog(@"Rewarded video clicked: %@", placementID);
}
@end
| Parameter Key | Type | Description | Example Value |
|---|---|---|---|
| kATBaiduRewardedVideoRewardType | NSString | Reward type 1 = Inflated reward 2 = Multiplied reward |
@"2" |
| kATBaiduRewardedVideoBasicReward | NSString | Inflated reward amount | @"100" |
| kATBaiduRewardedVideoBasicUnit | NSString | Inflated reward unit Customizable: Yuan, Coin, Diamond, etc. |
@"Yuan" |
| kATBaiduRewardedVideoAdvancedReward | NSString | Multiplied reward amount | @"200" |
| kATBaiduRewardedVideoAdvancedUnit | NSString | Multiplied reward unit | @"Yuan" |
| kATBaiduRewardedVideoMultiple | NSString | Reward multiple, recommended 2x or above | @"2" |
In the rewardedVideoDidRewardSuccessForPlacemenID:extra: callback, determine the reward type received by the user through the reward_type field in the extra dictionary:
| reward_type Value | Data Type | Description |
|---|---|---|
| @"1" | NSString | Inflated reward |
| @"2" | NSString | Multiplied reward |
reward_type field in the rewardedVideoDidRewardSuccessForPlacemenID:extra: callbackA: Print the extra dictionary in the rewardedVideoDidRewardSuccessForPlacemenID:extra: callback. If it contains the reward_type field, the two-stage reward feature is active.
A: Not necessarily. Users receive the basic reward after watching the video, but only receive the multiplied reward when they complete additional interactions (such as clicking on the ad). The specific interaction method is controlled by the Baidu ad platform.
A:
extra dictionary in the reward callback to check the reward_type value