RewardedVC.m
in DemoThe extra dictionary in this step supports passing in relevant parameters for configuring ads and your custom parameters. You can view more information about extra parameters here.
//Import header file
#import <AnyThinkRewardedVideo/AnyThinkRewardedVideo.h>
@interface RewardedVC () <ATAdLoadingDelegate, ATRewardedVideoDelegate>
@property (nonatomic, assign) NSInteger retryAttempt; // Retry attempt counter
@end
@implementation RewardedVC
//Ad placement ID
#define RewardedPlacementID @"b67f4ab93eb3a7"
//Scene ID, optional, can be generated in the backend. If not available, pass an empty string
#define RewardedSceneID @""
#pragma mark - Load Ad
- (void)loadAd {
NSMutableDictionary * loadConfigDict = [NSMutableDictionary dictionary];
// Optional integration, the following key parameters are applicable to server-side reward verification of ad platforms and will be passed through
[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];
// Start ad loading
[[ATAdManager sharedManager] loadADWithPlacementID:RewardedPlacementID extra:loadConfigDict delegate:self];
}
/// Ad placement loading completed
/// - Parameter placementID: Ad placement ID
- (void)didFinishLoadingADWithPlacementID:(NSString *)placementID {
// Reset retry attempts
self.retryAttempt = 0;
}
/// Ad placement loading failed
/// - Parameters:
/// - placementID: Ad placement ID
/// - error: Error information
- (void)didFailToLoadADWithPlacementID:(NSString *)placementID error:(NSError *)error {
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 ad
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, delaySec * NSEC_PER_SEC), dispatch_get_main_queue(), ^{
[self loadAd];
});
}
- The showCustomExt field of ATShowConfig in the show method also supports server callbacks. You need to add &ilrd={ilrd} to the reward callback address configured in the backend, and then the server can parse the show_custom_ext field. When you use showCustomExt as server-side rewards, the extra parameters when loading ads must include parameters for server callbacks (please refer to the example in the loading ads section above), otherwise the server will not receive callbacks.
- Statistics scene arrival rate, displayed in the backend's Data Reports -> Funnel Analysis Report -> Arrival at Ad Scene, called before showing ads.
#pragma mark - Show Ad
/// Show ad
- (void)showAd {
//Scene statistics function, displayed in the backend's Data Reports -> Funnel Analysis Report -> Arrival at Ad Scene, called before showing ads. Optional integration
[[ATAdManager sharedManager] entryRewardedVideoScenarioWithPlacementID:RewardedPlacementID scene:RewardedSceneID];
//Check if ready
if (![[ATAdManager sharedManager] rewardedVideoReadyForPlacementID:RewardedPlacementID]) {
[self loadAd];
return;
}
//Show configuration, Scene passes in the backend scene ID, if not available pass an empty string, showCustomExt parameter can pass in custom parameter string
ATShowConfig *config = [[ATShowConfig alloc] initWithScene:RewardedSceneID showCustomExt:@"testShowCustomExt"];
//Show ad
[[ATAdManager sharedManager] showRewardedVideoWithPlacementID:RewardedPlacementID config:config inViewController:self delegate:self];
}
#pragma mark - ATRewardedVideoDelegate
/// Reward success
/// - Parameters:
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)rewardedVideoDidRewardSuccessForPlacemenID:(NSString *)placementID extra:(NSDictionary *)extra {}
/// Rewarded ad video started playing
/// - Parameters:
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)rewardedVideoDidStartPlayingForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {}
/// Rewarded ad video finished playing
/// - Parameters:
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)rewardedVideoDidEndPlayingForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra {}
/// Rewarded ad video failed to play
/// - Parameters:
/// - placementID: Ad placement ID
/// - error: Error information
/// - extra: Extra information dictionary
- (void)rewardedVideoDidFailToPlayForPlacementID:(NSString*)placementID error:(NSError *)error extra:(NSDictionary *)extra {
// Preload
[self loadAd];
}
/// Rewarded ad closed
/// - Parameters:
/// - placementID: Ad placement ID
/// - rewarded: Whether reward was successful, YES means reward success callback has been triggered
/// - extra: Extra information dictionary
- (void)rewardedVideoDidCloseForPlacementID:(NSString *)placementID rewarded:(BOOL)rewarded extra:(NSDictionary *)extra {
// Preload
[self loadAd];
}
/// Rewarded ad was clicked
/// - Parameters:
/// - placementID: Ad placement ID
/// - extra: Extra information dictionary
- (void)rewardedVideoDidClickForPlacementID:(NSString*)placementID extra:(NSDictionary *)extra {}
/// Rewarded ad opened or jumped to deep link page
/// - Parameters:
/// - placementID: Ad placement ID
/// - extra: Ad placement ID
/// - success: Whether successful
- (void)rewardedVideoDidDeepLinkOrJumpForPlacementID:(NSString *)placementID extra:(NSDictionary *)extra result:(BOOL)success {}
Through registering the following delegate method in ATRewardedVideoDelegate
/// Reward distribution
- (void)rewardedVideoDidRewardSuccessForPlacemenID:(NSString *)placementID extra:(NSDictionary *)extra {
}
Fully automatic loading : TopOn has launched a one-stop solution that intelligently determines the timing for preloading and caching the next ad based on the user's usage status and the progress of ad consumption.