> For the complete documentation index, see [llms.txt](https://docs.blueseasx.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.blueseasx.com/client-bidding/ios/rewarded-ads.md).

# Rewarded Ads

### **Step1. Load**

On the BlueSea console, create client bidding placement for the ad request. Please note the client bidding placements don’t support floor price setup.

<div align="left"><img src="/files/SZDBlLKNXJKe1EUKjIiL" alt="" height="406" width="543"></div>

Before requesting ads, please ensure that the SDK has been initialized.

To request rewarded ads, declare a `BSXMediationInfo` object. This object should include the ad mediation platform, the mediation version, and the BlueSea Adapter version used when requesting the ads. If you are integrating BlueSea SDK through your own mediation platform, it is recommended to declare the `BSXMediationInfo` object and pass in the mediation information to facilitate monetization data management and channel monetization optimization.

```
BSXMediationInfo *mediationInfo = [[BSXMediationInfo alloc] initWithMediationName:@"<in-house or mediation>" mediationVersion:@"<mediation version-name>" adapterVersion:@"<adapter-version-name>"];
```

* **\<in house or mediation name>**: Pass the value as "in-house"&#x20;
* **\<mediation-version-name>**: Pass the version number of your app or meditation
* **\<adapter-version-code>**: Pass the version number of the adapter.

Call the `[BlueSeaSDK loadRewardVideoAdWithPlacementId:mediationInfo:delegate:]` method, pass the ad's Placement ID, and initiate the ad request:

```
[BlueSeaSDK loadRewardVideoAdWithPlacementId:@"<BlueSea-pid>" mediationInfo:mediationInfo delegate:self];
@interface ViewController () <BSXRewardVideoAdDelegate, BSXRewardVideoAdLoadDelegate>
@end
@implementation ViewController () 
#pragma mark - BSXRewardVideoAdLoadDelegate
- (void)didBSXRewardVideoAdLoadError:(BSXAdError*)error {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = nil;
}
- (void)didBSXRewardVideoAdLoaded:(BSXRewardVideoAd *)ad {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = ad;
    [self.rewardVideoAd setDelegate:self];
}
@end

```

`BSXRewardVideoAdLoadDelegate` callback:

* `- (void)didBSXRewardVideoAdLoadError:(BSXAdError *)error`: Indicates that no ads were filled. This may be due to the advertiser not bidding or other issues. You can check the error code and message using `AdError.errorCode` and `AdError.errorMsg`. For details on error codes, refer to [Test & Error Handling](/client-bidding/ios/test-and-error-handling.md)
* `- (void)didBSXRewardVideoAdLoaded:(BSXRewardVideoAd *)ad`: Indicates that the ad was successfully filled and returns an instance of the `BSXRewardVideoAd` object.

The following example shows how to fully load a rewarded ad in the `viewDidLoad` method of `ViewController`:

```
@interface ViewController () <BSXRewardVideoAdDelegate, BSXRewardVideoAdLoadDelegate>
@end
@implementation ViewController () 
- (void)viewDidLoad {
    [super viewDidLoad];
    BSXMediationInfo *mediationInfo = [[BSXMediationInfo alloc] initWithMediationName:@"<in-house or mediation>" mediationVersion:@"<mediation version-name>" adapterVersion:@"<adapter-version-name>"];
    [BlueSeaSDK loadRewardVideoAdWithPlacementId
:@"<BlueSea-pid>" mediationInfo:mediationInfo delegate:self];
}
#pragma mark - BSXRewardVideoAdLoadDelegate
- (void)didBSXRewardVideoAdLoadError:(BSXAdError*)error {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = nil;
}
- (void)didBSXRewardVideoAdLoaded:(BSXRewardVideoAd *)ad {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = ad;
    [self.rewardVideoAd setDelegate:self];
}
@end
```

### **Step2. Auction**

When you receive a `(void)didBSXRewardVideoAdLoaded:(BSXRewardVideoAd *)ad` callback, use the `Price` method to get the price for this ad. (double type, unit: eCPM (USD) )

```
double price = [BSXRewardVideoAd price];
```

The client reports the auction result to BlueSea via the following two methods of `RewardVideoAd`:

```
// BlueSea win，then publisher pass the following info
* @param minBidder the bidder name of second highest price
* @param auctionMinToWin Second-highest bid price, double type, unit: eCPM, rounded to 4 decimal places
- (void)notifyAdWinWithMinBidder:(NSString *)minBidder
                 auctionMinToWin:(double)auctionMinToWin;


// BlueSea loss，then publisher pass the following info
* @param winBidder Winning bidder name — string
* @param auctionPrice Highest bid price — double, unit: eCPM, rounded to 4 decimal places
* @param auctionLossCode BlueSea loss reason — reason why BlueSea lost the auction
*/
- (void)notifyAdLossWithWinBidder:(NSString *)winBidder
                     auctionPrice:(double)auctionPrice
                  auctionLossCode:(int32_t)auctionLossCode;
```

**Auction Loss Code**

<table data-header-hidden data-search="false"><thead><tr><th width="125.0703125"></th><th></th></tr></thead><tbody><tr><td><strong>Value</strong></td><td><strong>Definition</strong></td></tr><tr><td>1</td><td>Internal Error</td></tr><tr><td>2</td><td>Impression Opportunity Expired</td></tr><tr><td>9</td><td>Missing Bid Price</td></tr><tr><td>100</td><td>Bid was Below Auction Floor</td></tr><tr><td>102</td><td>Lost to Higher Bid</td></tr><tr><td>1000+</td><td>Publisher specific values; should be communicated with BlueSea beforehand.</td></tr></tbody></table>

### **Step3. Show**

After receiving the `- (void)didBSXRewardVideoAdLoaded:(BSXRewardVideoAd *)ad` callback, register the ad listener using the `[BSXRewardVideoAd setDelegate:]` method:

```
@interface ViewController () <BSXRewardVideoAdDelegate, BSXRewardVideoAdLoadDelegate>
@end
@implementation ViewController () 
- (void)viewDidLoad {
    [super viewDidLoad];
    BSXMediationInfo *mediationInfo = [[BSXMediationInfo alloc] initWithMediationName:@"<in-house or mediation>" mediationVersion:@"<mediation version-name>" adapterVersion:@"<adapter-version-name>"];
    [BlueSeaSDK loadRewardVideoAdWithPlacementId
:@"<BlueSea-pid>" mediationInfo:mediationInfo delegate:self];
}
#pragma mark - BSXRewardVideoAdLoadDelegate
//ad load failed
- (void)didBSXRewardVideoAdLoadError:(BSXAdError*)error {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = nil;
}
//ad load succeeded
- (void)didBSXRewardVideoAdLoaded:(BSXRewardVideoAd *)ad {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = ad;
    [self.rewardVideoAd setDelegate:self];
}
#pragma mark - BSXRewardVideoAdDelegate
// ad display error
- (void)didBSXRewardVideoAd:(BSXRewardVideoAd *)ad displayError:(BSXAdError *)error {
    if (self.rewardVideoAd) {
        [self.rewardVideoAd destroy];
    }
    self.rewardVideoAd = nil;
}
// an ad impression occurred
- (void)didBSXRewardVideoAdDisplayed:(BSXRewardVideoAd *)ad {
    NSLog(@"RewardVideoAd displayed.");
}
// the ad was clicked 
- (void)didBSXRewardVideoAdClicked:(BSXRewardVideoAd *)ad {
    NSLog(@"RewardVideoAd clicked.");
}
//the ad was opened
- (void)didBSXRewardVideoAdOpened:(BSXRewardVideoAd *)ad {
    NSLog(@"RewardVideoAd opened.");
}
// the ad was closed
- (void)didBSXRewardVideoAdClosed:(BSXRewardVideoAd *)ad {
    NSLog(@"RewardVideoAd closed.");
} 
// a reward had been granted
- (void)didBSXRewardVideoAdRewarded:(BSXRewardVideoAd *)ad {
    NSLog(@"RewardVideoAd rewarded.");
}
@end
```

Before displaying the ad, use the `[BSXRewardVideoAd isExpired]` method to check if the ad has expired (the ad's validity period is typically 60 minutes). If the ad has expired, you can request a new one. If it has not expired, you can use the `[BSXRewardVideoAd showWithController:]` method to display the rewarded video ad:

```
[self.rewardVideoAd showWithController:self];
```

### **Step4. Destroy**

The SDK will automatically destroy the ad after detecting that the user has closed it.
