Links

Rewarded Ads

This guide shows how to display Rewarded Ads in your application.

What are Rewarded Ads?

Rewarded Ad Units reward a user within the app in exchange for completing the ad. This opt-in ad unit provides a less-disruptive user experience along with high engagement from users.

How to Display Rewarded Ads

Integrate & Initialize HyprMX

Before you start, make sure you have correctly integrated and initialized the HyprMX SDK. To integrate and initialize HyprMX, see our Setup Guide.

Loading Rewarded Ads

HyprMX utilizes placements to load and display an ad. Placements are used to represent a point in your application's workflow where you'd like to show an ad. To load an ad to a placement, follow the steps below.
If you don't have your placement information, please reach out to your account manager to configure your rewarded placements. In return, they will provide the names of the new placements.
1. To show an ad, use the getPlacement API to retrieve a placement from HyprMX, then set a placementDelegate.
Swift
Objective-C
let rewardedPlacement = HyprMX.getPlacement("REWARDED")
rewardedPlacement.placementDelegate = self
HyprMXPlacement *rewardedPlacement = [HyprMX getPlacement:@"REWARDED"];
rewardedPlacement.placementDelegate = self;
2. To check for availability, run the following.
Swift
Objective-C
rewardedPlacement.loadAd()
[rewardedPlacement loadAd];
loadAd() will call back to your placementDelegate with:
  • adAvailableForPlacement:/adAvailable(for placement:) when an ad is available.
  • adNotAvailableForPlacement:/adNotAvailable(for placement:) when there is no inventory.
3. To receive ad load and display status, implement the HyprMXPlacementDelegate:
Swift
Objective-C
/** Called in response to loadAd when there is an ad to show */
func adAvailable(for placement: HyprMXPlacement) {
}
/** Called in response to loadAd when there's no ad to show */
func adNotAvailable(for placement: HyprMXPlacement) {
}
/** Called when ad loaded is no longer available for this placement */
func adExpired(for placement: HyprMXPlacement) {
}
/** Called upon conclusion of any ad presentation attempt */
func adDidClose(for placement: HyprMXPlacement, didFinishAd finished: Bool) {
}
/** Called when user has earned a reward. */
func adDidReward(for placement: HyprMXPlacement, rewardName: String?, rewardValue: Int) {
}
/** Called immediately before attempting to present an ad. */
func adWillStart(for placement: HyprMXPlacement) {
}
/** Called when an error occurs during ad presentation. */
func adDisplayError(_ error: Error, placement: HyprMXPlacement) {
}
/** Called in response to loadAd when there is an ad to show */
- (void)adAvailableForPlacement:(HyprMXPlacement *)placement {
}
/** Called in response to loadAd when there's no ad to show */
- (void)adNotAvailableForPlacement:(HyprMXPlacement *)placement {
}
/** Called when ad loaded is no longer available for this placement */
- (void)adExpiredForPlacement:(HyprMXPlacement *)placement {
}
/** Called upon conclusion of any ad presentation attempt */
- (void)adDidCloseForPlacement:(HyprMXPlacement *)placement didFinishAd:(BOOL)finished {
}
/** Called when user has earned a reward. */
- (void)adDidRewardForPlacement:(HyprMXPlacement *)placement rewardName:(NSString *)rewardName rewardValue:(NSInteger)rewardValue {
}
/** Called immediately before attempting to present an ad. */
- (void)adWillStartForPlacement:(HyprMXPlacement *)placement {
}
/** Called when an error occurs during ad presentation. */
-(void)adDisplayError:(NSError *)error placement:(HyprMXPlacement *)placement {
}
HyprMX holds a weak reference to the placement delegate, so you must be sure to retain the delegate.

Displaying Rewarded Ads

1. Before calling showAdFromViewController: on a placement you should confirm the ad state is still valid by running the following.
Swift
Objective-C
rewardedPlacement.isAdAvailable()
[rewardedPlacement isAdAvailable]
Once an ad network has an available video, you will be ready to show the video to your users. Before you display the ad, make sure to pause any game action, including audio, to ensure the best experience for your users. You can disable them when you get the adWillStartForPlacement:/adWillStart(for placement:) callback and re-enable when you get the adDidCloseForPlacement:/adDidClose(for placement:).
2. You can supply your current UIViewController when calling showAdFromViewController: for HyprMX to present from, or pass nil and HyprMX will present from the keyWindow. If your App supports multi-window, it is recommended to always provide a View Controller to present from.
Swift
Objective-C
if rewardedPlacement.isAdAvailable() {
rewardedPlacement.showAd(from: self)
}
if ([rewardedPlacement isAdAvailable]) {
[rewardedPlacement showAdFromViewController:self];
}
showAdFromViewController: will begin the presentation of an ad.
The ad will call back to your placementDelegate to provide the state on the ad display:
  • adWillStartForPlacement:/adWillStart(for placement:) is called immediately before attempting to present the ad to the UI.
  • adDidCloseForPlacement:/adDidClose(for placement:) is called when the ad is closed.
  • adDisplayErrorForPlacement:placement:/adDisplayError(_ error: Error, placement: HyprMXPlacement) is called when an error occurs presenting the ad, and will be followed by adDidCloseForPlacement:/adDidClose(for placement:)
  • adDidRewardForPlacement:rewardName:rewardValue:/adDidReward(for placement:, rewardName:, rewardValue:) is called when a user successfully completes a rewarded ad, and will provide you with the reward name and value.
If you'd like, we can send server-to-server calls when ads are completed. Contact your account manager at HyprMX for more details.