Rewarded Ads
Ad Request
Placement
Create placement from AdFormat with your parameters:
- Swift
- Objective-C
let placement = try? BidMachineSdk.shared.placement(.rewarded) {
$0.withPlacementId("")
$0.withCustomParameters([String:Any]())
}
NSError *error = nil;
BidMachinePlacement *placement = [BidMachineSdk.shared placement:BidMachineAdFormat.rewarded
error:&error
builder:^(id<BidMachinePlacementBuilderProtocol> _Nonnull builder) {
[builder withPlacementId:@""];
[builder withCustomParameters:@{}];
}];
| Parameter | Type | Description |
|---|---|---|
placementId | String | Placement ID |
customParameters | [String: Any] / NSDictionary | Passed directly to the server |
AdFormat
The placement format is defined by static properties of the AdFormat class:
- Swift
- Objective-C
@objc(BidMachineAdFormat)
final public class AdFormat : NSObject {
@objc public static var rewarded: BidMachine.AdFormat { get }
@objc public static var rewardedStatic: BidMachine.AdFormat { get }
@objc public static var rewardedVideo: BidMachine.AdFormat { get }
}
@interface BidMachineAdFormat (SWIFT_EXTENSION(BidMachine))
+ (BidMachineAdFormat * _Nonnull)rewarded;
+ (BidMachineAdFormat * _Nonnull)rewardedStatic;
+ (BidMachineAdFormat * _Nonnull)rewardedVideo;
@end
Available rewarded formats
| Format | Description |
|---|---|
rewarded | Combines both VAST (video) and MRAID (static) formats |
rewardedVideo | VAST video ads only |
rewardedStatic | MRAID static ads only |
General Request
Auction request is used to set bidding parameters: The request is created with a special placement and your parameters
- Swift
- Objective-C
let request = BidMachineSdk.shared.auctionRequest(placement: placement) {
$0.withUnitConfigurations([BidMachineUnitConfiguration]())
$0.appendPriceFloor(Double(10), UUID().uuidString)
}
BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement builder: ^(id<BidMachineAuctionRequestBuilderProtocol> _Nonnull builder) {
[builder withUnitConfigurations:@[]];
[builder appendPriceFloor:10.0 identifier:[[NSUUID UUID] UUIDString]];
}];
| Parameter | Type | Description |
|---|---|---|
unitConfigurations | [BidMachineUnitConfiguration] | Header bidding unit configurations |
priceFloor | (Double, String) | Price floor (value and identifier) |
Client Bidding Request
Bid Token
With S2S integration, you will need a token that you need to transfer in the request. To get a token, you can use method:
- Swift
- Objective-C
BidMachineSdk.shared.token(placement: placement) { token in }
[BidMachineSdk.shared tokenWithPlacement:placement completion:^(NSString *token) {
}];
Bid Payload
After completing the server-side auction, you will receive a Base64-encoded payload string, which must be passed as a parameter to the AuctionRequest.
- Swift
- Objective-C
let request = BidMachineSdk.shared.auctionRequest(placement: placement) {
$0.withPayload("")
}
BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement builder: ^(id<BidMachineAuctionRequestBuilderProtocol> _Nonnull builder) {
[builder withPayload:@""];
}];
| Parameter | Type | Description |
|---|---|---|
payload | String | Custom BidMachine payload string |
Ad Display
The ad object handles downloading and displaying ads.
Prepare the ad object
Request an ad using your auction request:
- Swift
- Objective-C
BidMachineSdk.shared.rewarded(request: request) { [weak self] ad, error in
guard let self else { return }
self.rewarded = ad
}
__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] rewardedWithRequest:request
completion:^(BidMachineRewarded *ad, NSError * _Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
strongSelf.rewarded = ad;
}];
The loaded ad provides auctionInfo and requestInfo.
The auctionInfo contains information about the auction, such as the winning bidder, price, and other relevant details.
The auctionInfo is described here.
Delegate
Assign the delegate to receive ad events:
- Swift
- Objective-C
ad.delegate = self
ad.delegate = self;
Implement BidMachineAdDelegate methods:
- Swift
- Objective-C
func didLoadAd(_ ad: BidMachineAdProtocol) {}
func didFailLoadAd(_ ad: BidMachineAdProtocol, _ error: Error) {}
func didPresentAd(_ ad: BidMachineAdProtocol) {}
func didFailPresentAd(_ ad: BidMachineAdProtocol, _ error: Error) {}
func didDismissAd(_ ad: BidMachineAdProtocol) {}
func willPresentScreen(_ ad: BidMachineAdProtocol) {}
func didDismissScreen(_ ad: BidMachineAdProtocol) {}
func didUserInteraction(_ ad: BidMachineAdProtocol) {}
func didExpired(_ ad: BidMachineAdProtocol) {}
func didTrackImpression(_ ad: BidMachineAdProtocol) {}
func didTrackInteraction(_ ad: BidMachineAdProtocol) {}
func didReceiveReward(_ ad: BidMachineAdProtocol) {}
- (void)didLoadAd:(id<BidMachineAdProtocol>)ad {}
- (void)didFailLoadAd:(id<BidMachineAdProtocol>)ad :(NSError *)error {}
- (void)didPresentAd:(id<BidMachineAdProtocol>)ad {}
- (void)didFailPresentAd:(id<BidMachineAdProtocol>)ad :(NSError *)error {}
- (void)didDismissAd:(id<BidMachineAdProtocol>)ad {}
- (void)willPresentScreen:(id<BidMachineAdProtocol>)ad {}
- (void)didDismissScreen:(id<BidMachineAdProtocol>)ad {}
- (void)didUserInteraction:(id<BidMachineAdProtocol>)ad {}
- (void)didExpired:(id<BidMachineAdProtocol>)ad {}
- (void)didTrackImpression:(id<BidMachineAdProtocol>)ad {}
- (void)didTrackInteraction:(id<BidMachineAdProtocol>)ad {}
- (void)didReceiveReward:(id<BidMachineAdProtocol>)ad {}
Loading and presenting rewarded ads
Make sure both the delegate and controller are set before loading.
Example of rewarded ad loading:
- Swift
- Objective-C
guard let placement = try? BidMachineSdk.shared.placement(.rewarded) else { return }
let request = BidMachineSdk.shared.auctionRequest(placement: placement)
BidMachineSdk.shared.rewarded(request: request) { [weak self] ad, error in
guard let self = self else {
return
}
self.rewarded = ad
self.rewarded.controller = self
self.rewarded.delegate = self
self.rewarded.loadAd()
}
NSError *error = nil;
BidMachinePlacement *placement = [BidMachineSdk.shared placement:BidMachineAdFormat.rewarded
error:&error
builder:nil];
if (!placement) {
return;
}
BidMachineAuctionRequest *request = [[BidMachineSdk shared] auctionRequestWithPlacement:placement
builder:nil];
__weak typeof(self) weakSelf = self;
[[BidMachineSdk shared] rewardedWithRequest:request
completion:^(BidMachineRewarded *ad, NSError * _Nullable error) {
__strong typeof(weakSelf) strongSelf = weakSelf;
if (!strongSelf) {
return;
}
strongSelf.rewarded = ad;
strongSelf.rewarded.controller = strongSelf;
strongSelf.rewarded.delegate = strongSelf;
[strongSelf.rewarded loadAd];
}];
Present the ad:
- Swift
- Objective-C
rewarded.presentAd()
[self.rewarded presentAd];