> 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/ios/rewarded-ads.md).

# Rewarded Ads

### **Step1. Load**

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. If you are integrating BlueSea SDK through third-party mediations like MAX, LevelPlay, etc., you can skip this step.

```
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" or the specific mediation platform name.
* `<mediation-version-name>`: Pass the version number of the mediation SDK.
* `<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](/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. 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.");
}
```

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];
```

### **Step3. Destroy**

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