Aller au contenu principal
Version: 5.x.x

Rewarded Ads

Overview

A rewarded ad is an ad that user can choose to watch in exchange for some rewards.

Create a Rewarded Ad

To create a rewarded ad, instantiate an instance of RewardedAd with a placement Id.


#import <BlueStackSDK/BlueStackSDK.h>

@interface ViewController ()

@property (strong, nonatomic) RewardedAd *rewardedAd;

@end

@implementation ViewController

- (void)viewDidLoad {
self.rewardedAd = [[RewardedAd alloc] initWithPlacementID:@"REWARDED_PLACEMENT_ID"];
}

@end

Load a Rewarded Ad

Rewarded ad can be loaded by calling load(requestOptions:) method with a RequestOptions instance for supplying targeting information or simply calling load() method.

RequestOptions *requestOptions = [[RequestOptions alloc] initWithAge:@(25)
location:[[CLLocation alloc] initWithLatitude:48.87610 longitude:10.453]
gender:GenderMale
keyword:@"brand=myBrand;category=sport"
contentUrl:@"https://my_content_url.com/"];
[self.rewardedAd loadWithRequestOptions:requestOptions];
// Or
// [self.rewardedAd load];

Ad Events

Registering for Rewarded Ad events

Rewarded ad provides lifecycle events and other full-screen events through RewardedAdDelegate and FullScreenDelegate. Use following code to listen to all the events that rewarded ad invokes.

self.rewardedAd.delegate = self;
self.rewardedAd.fullScreenDelegate = self;

Rewarded ad lifecycle events

RewardedAdDelegate has the following methods for listening to rewarded ad's lifecycle events.

- (void)didLoadRewardedAd:(RewardedAd *)ad {
NSLog(@"Rewarded ad loaded");
}

- (void)rewardedAd:(RewardedAd *)ad didFailedToLoadWithError:(NSError *)error {
NSLog(@"Failed to load rewarded ad with error: %@", error.localizedDescription);
}

You can get the reward information by implementing the onRewardEarned(_ ad: , _ reward:) delegate method.

- (void)rewardedAd:(RewardedAd *)ad didEarnedReward:(Reward *)reward {
NSLog(@"Reward Earned: %f", reward.amount.floatValue);
}

Rewarded ad full-screen events

FullScreenDelegate has the following methods for receiving full-screen content events.

- (void)didDisplayAd:(id<FullScreenDisplayableAd>)ad {
NSLog(@"Rewarded ad displayed");
}

- (void)ad:(id<FullScreenDisplayableAd>)ad didFailedToDisplayWithError:(NSError *)error {
NSLog(@"Failed to display rewarded ad with error: %@", error.localizedDescription);
}

- (void)didClickAd:(id<FullScreenDisplayableAd>)ad {
NSLog(@"Rewarded ad clicked.");
}

- (void)didDismissAd:(id<FullScreenDisplayableAd>)ad {
NSLog(@"Rewarded ad dismissed");
}

Show a Rewarded Ad

To show a rewarded ad call show(fromRootViewController:) method on RewardedAd instance with an optional root view controller.

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

Destroying Rewarded Ad

You need to keep a strong reference to the RewardedAd instance. You can release it when you are done showing the rewarded ad (Rewarded ad has dismissed) simply by setting it to nil.

self.rewardedAd = nil;
info

We discourage to create and load new rewarded ad instance in load failed callback onAdFailedToLoad(_ ad: , _ error:).