Wiki
Clone wikiFullscreen and RV Sample / AATKit 3 rewarded video migration
Rewarded Video Integration
Rewarded Video
Important: Only one rewarded video can load at the same time. In other words, it is not possible to load and buffer more than one rewarded video.
Create RewardedVideo Placement
Creating a rewarded video placement
Instead of:
Objective-C:
[AATKit createRewardedVideoPlacement:@"RewardedVideo"];
AATKit.createRewardedVideoPlacement("RewardedVideo")
Use:
Objective-C:
[AATSDK createRewardedVideoPlacementWithName:@"RewardedVideo"];
AATSDK.createRewardedVideoPlacement(name: "RewardedVideo")
Request Ad
You can request ads for the rewarded video placement either automatically or manually.
Automatic Reload
Note: The rewarded video placement fires aatHaveAd(:)
delegate method only once per loaded ad. So, Before starting the auto-reload, you should check for ads from the previous load/auto-reload using the placement has ad API.
To automatically load rewarded video Placement you can use the following API:
Instead of:
Objective-C:
// Start rewarded video placement auto-reloading to automatically // download a new rewarded video ad after presenting the current one. [AATKit startPlacementAutoReload:self.rewardedVideoPlacement];
// Start rewarded video placement auto-reloading to automatically // download a new rewarded video ad after presenting the current one. AATKit.startPlacementAutoReload(rewardedVideoPlacement)
Use:
Objective-C:
// Start rewarded video placement auto-reloading to automatically // download a new rewarded video ad after presenting the current one. [self.rewardedVideoPlacement startAutoReload];
// Start rewarded video placement auto-reloading to automatically // download a new rewarded video ad after presenting the current one. rewardedVideoPlacement.startAutoReload()
In this scenario, a rewarded video Ad is loaded automatically. It is reloaded only if a previously rewarded video Ad has already been displayed.
Manual Load
To manually load a rewarded video ad, the following method can be used:
Instead of:
Objective-C:
[AATKit reloadPlacement:rewardedVideoPlacement];
AATKit.reload(rewardedVideoPlacement)
Use:
Objective-C:
[self.rewardedVideoPlacement reload];
placement.reload()
Displaying a Rewarded Video Ad
Displaying a rewarded video ad can be done in two ways.
First, the AATKit can be told to display a rewarded video placement using the following method:
Instead of:
Objective-C:
[AATKit showPlacement:rewardedVideoPlacement];
AATKit.show(rewardedVideoPlacement)
Use:
Objective-C:
[self.rewardedVideoPlacement show];
rewardedVideoPlacement.show()
The method will return a bool value indicating whether the rewarded video placement could be displayed or not. This means it could be filled with an Ad by an Ad network. Thus, it is possible to use the following construct to react based on whether the rewarded video placement was displayed or not:
Instead of:
Objective-C:
#!objective-c if ( ! [AATKit showPlacement:rewardedVideoPlacement] ) { NSLog(@"rewarded video Ad could not be displayed"); }
#!swift if !AATKit.show(rewardedVideoPlacement) { print("rewarded video Ad could not be displayed") }
Use:
Objective-C:
#!objective-c if ( ! [self.rewardedVideoPlacement show] ) { NSLog(@"rewarded video Ad could not be displayed"); }
#!swift if !rewardedVideoPlacement.show() { print("rewarded video Ad could not be displayed") }
Calling the method showPlacement
does increase the AdSpace count, which is used to calculate the fill rate. An AdSpace expresses the intention to show an ad.
Assign a specific view controller to a placement
Setting a view controller during initialization of the AATKit, or by using the method + (void) setViewController:(nullable UIViewController*)con;
sets a global view controller used by all placements.
It's also possible to assign a placement-specific view controller, by using the following method:
Instead of:
Objective-C:
[AATKit setPlacementViewController:self forPlacement:rewardedVideoPlacement];
[AATKit setPlacementViewController:self forPlacement:rewardedVideoPlacement];
Use:
Objective-C:
[AATSDK controllerViewDidAppearWithController:self];
Swift:
#!swift AATSDK.controllerViewDidAppear(controller: self)
In the ViewController's viewWillDisappear
method, you should do the following:
Objective-C:
[AATSDK controllerViewWillDisappear];
Swift:
#!swift AATSDK.controllerViewWillDisappear()
Listening to Events
To register for the placement events, set the delegate property on AATRewardedVideoPlacement
to an object that implements the AATRewardedVideoPlacementDelegate
protocol.
Objective-C:
[self.placement setDelegate:self];
Swift:
placement.delegate = self
Implementing AATRewardedVideoPlacementDelegate
func aatHaveAd() { /// This method will be called when there is an ad } func aatNoAd() { /// This method will be called when there is no ad available } func aatAdCurrentlyDisplayed() { /// This method will be called with the ad display event } func aatResumeAfterAd() { /// This method will be called when the app resumes after displaying an ad } func aatUserEarnedIncentive(aatReward: AATReward) { /// This method will be called when the user gets rewarded }
Has Ad
The rewarded video placement provides an API to check if it has a loaded ad.
Objective-C:
BOOL hasAd = [self.placement hasAd];
let hasAd = placement.hasAd()
Listening to statistics events
AATStatisticsDelegate is an optional delegate you can implement if you need to get notified about statistics events. and pass it to placement while creating it using this
Use:
placement.statisticsDelegate = self
for more info about it please refer to AATStatisticsDelegate Guide
Updated