iOS Rewarded Video

Rewarded Video Ad Unit

Rewarded video ads give users the choice to watch a video ad in return for a reward, such as points, lives or free content, encouraging the user to stay in the app and driving increased ad revenue.

Rewarded video works almost identically to interstitial video.

1. Import Libraries
@import ChocolatePlatform_SDK_Core;
2. Declare a ChocolateRewardedAd instance with property in your app’s UIViewController
@property(nonatomic,strong) ChocolateRewardedAd *rewardedAd;
3. Initialize ChocolateRewardedAd

self.rewardedAd = [[ChocolateRewardedAd alloc] initWithDelegate:self];

Note: you must initialize the Chocolate SDK with the API key provided by us, as described above. No ads will be displayed otherwise.

4. Load the ad

[self.rewardedAd load];
5. Implement event listeners for ChocolateAdDelegate.


# pragma mark - ChocolateAdDelegate Methods

-(void)onChocolateAdLoaded:(ChocolateAd *)ad {}

-(void)onChocolateAdLoadFailed:(ChocolateAd *)ad because:(ChocolateAdNoAdReason)reason {}
-(void)onChocolateAdShown:(ChocolateAd *)ad {}
-(void)onChocolateAdClosed:(ChocolateAd *)ad {}

-(void)onChocolateAdFailedToStart:(ChocolateAd *)ad because:(ChocolateAdNoAdReason)reason {}
-(void)onChocolateAdReward:(NSString *)rewardName amount:(NSInteger)rewardAmount {}
6. Set the reward data

This is information about the reward the user is expected to get for viewing an ad. This information includes the following:

• Amount – Virtual Currency Amount – e.g. 10

• RewardName – Virtual Currency Name – e.g. Coins or Free Articles

• UserID – This is user ID of your user login system – e.g. Chocolate1

• SecretKey – You can get this from account manager or portal – e.g. XYZ

The data is captured in a ChocolateReward object. You first obtain a blank instance, and fill it with values, and then pass it to your ChocolateRewardedAd object:


ChocolateReward *reward = [ChocolateReward blankReward];
reward.rewardName = @"coins";
reward.rewardAmount = 10;
reward.userID = @"Chocolate1";
reward.secretKey = @"XYZ"

self.rewardedAd.reward = reward;

You need to set the reward object on the ad before you show the ad.

7. Show reward ad by calling showFrom: method


 [self.rewardedAd showFrom:self];

Reward Handling

You have two options in terms of reward handling.

Server Callback

Server Callbacks allow user rewards to be sent directly from our servers to yours. Our servers send a real-time notification as soon as a reward is logged in our system. Your servers will then need to be able to process the reward as soon as it comes in, and then populate the reward out to the user.

The main benefit of server-side callbacks is that all traffic directly related to crediting the reward is completely outside the control or visibility of the user. Because there is no sensitive traffic going through the user’s device, there is less chance for fraud.

For server callback setup, please log in to portal and utilize the following resources:

• Callback Security Secret – If you want to enable verification via ‘digest’, you will need this.

• Macro Details List – Shows list of supported macros. Also find the details of ‘digest’ from here.

• Callback Tester – Use this tool to have our server ping your server to test the connectivity between our server and yours.

Client Callback

If you plan on handling the user rewarded via your own code and your systems, please choose this option. You should be able to use the callback below.


-(void)onChocolateAdReward:(NSString *)rewardName amount:(NSInteger)rewardAmount {
    //handle the reward
}

Note: if you are using multiple instances of Chocolate ads (whether of the same ad unit or different ad units), make sure the callback is acting appropriately for the ad involved. The simplest way is to check the ad’s identity:


-(void)onChocolateAdLoaded:(ChocolateAd *)ad {
    if(ad == self.rewardedAd) {
        //the declared rewarded ad is loaded
    } else {
        //another ad, process appropriately for that ad
    }
}
Example sample code

@import ChocolatePlatform_SDK_Core;

@interface RewardExampleViewController ()

@property(nonatomic,strong) ChocolateRewardedAd * rewardedAd;

@end
@implementation RewardExampleViewController
- (void)viewDidLoad {
 [super viewDidLoad];
 
 self.rewardedAd = [[ChocolateRewardedAd alloc] initWithDelegate:self];
 [self.rewardedAd load];
}

# pragma mark - ChocolateAdDelegate Methods

-(void)onChocolateAdLoaded:(ChocolateAd *)ad {
    ChocolateReward *reward = [ChocolateReward blankReward];
    reward.rewardName = @"coins";
    reward.rewardAmount = 10;
    reward.userID = @"Chocolate1";
    reward.secretKey = @"XYZ"

    self.rewardedAd.reward = reward;
    [self.rewardedAd showFrom:self];
}

-(void)onChocolateAdLoadFailed:(ChocolateAd *)ad because:(ChocolateAdNoAdReason)reason {}
-(void)onChocolateAdShown:(ChocolateAd *)ad {}
-(void)onChocolateAdClosed:(ChocolateAd *)ad {}

-(void)onChocolateAdFailedToStart:(ChocolateAd *)ad because:(ChocolateAdNoAdReason)reason {}
-(void)onChocolateAdReward:(NSString *)rewardName amount:(NSInteger)rewardAmount {
    NSLog(@"Received %ld %@", rewardAmount, rewardName);
    //handle reward for your app
}

@end
How to turn on ads on your ad unit

Please send us your sample app with the integrated code. We will help you validate the SDK setup and turn on the demand.