Leaderboard Ads will be rendered using MPAdView through the HyBidMoPubHeaderBiddingLeaderboardCustomEvent adapter.
Requirements
Ad Zone IDfrom the PubNative Publisher DashboardMoPub Ad Unit IDfor the Ad Placement that you want to request.
Demo App
You can find a demo app with code samples for this type of integration here.
Create MoPub AdView
- Declare a
MPAdView *moPubLeaderboardproperty.
var moPubLeaderboard = MPAdView()
@property (nonatomic, strong) MPAdView *moPubLeaderboard;
- Instantiate the property that you have declared, passing in your
MoPub Ad Unit ID.
self.moPubLeaderboard = MPAdView(adUnitId: "<YOUR MoPUB AD UNIT ID HERE>")
self.moPubLeaderboard.frame = CGRect(x: 0, y: 0, width: 728, height: 90)
self.moPubLeaderboard = [[MPAdView alloc] initWithAdUnitId:@"<YOUR MoPUB AD UNIT ID HERE>"];
[self.moPubLeaderboard setFrame:CGRectMake(0, 0, 728, 90)];
- Register your view controller as the
moPubLeaderboard's delegate (MPAdViewDelegate).
self.moPubLeaderboard.delegate = self
self.moPubLeaderboard.delegate = self;
- Make sure to call
stopAutomaticallyRefreshingContentsmethod.
self.moPubLeaderboard.stopAutomaticallyRefreshingContents()
[self.moPubLeaderboard stopAutomaticallyRefreshingContents];
- Implement the
MPAdViewDelegate'sviewControllerForPresentingModalViewmethod. Typically your controller can simply returnself.
extension ViewController : MPAdViewDelegate
{
func viewControllerForPresentingModalView() -> UIViewController!
{
return self
}
}
#pragma mark - <MPAdViewDelegate>
- (UIViewController *)viewControllerForPresentingModalView
{
return self;
}
For more information about MoPub Leaderboard integration, you can refer to the MoPub Documentation as well.
Create HyBid Ad Request
- Import
HyBidinto your class.
import HyBid
#import <HyBid/HyBid.h>
- Declare a
HyBidAdRequest *leaderboardAdRequestproperty.
var leaderboardAdRequest = HyBidAdRequest()
@property (nonatomic, strong) HyBidAdRequest *leaderboardAdRequest;
- Instantiate the property that you have declared. Before making a request, set its
adSizeproperty. After this, you can request an Ad by, passing yourAd Zone IDand also your registered view controller as theleaderboardAdRequest's delegate (HyBidAdRequestDelegate).
self.leaderboardAdRequest.adSize = HyBidAdSize.size_728x90
self.leaderboardAdRequest.requestAd(with: self, withZoneID: <YOUR AD ZONE ID HERE>)
self.leaderboardAdRequest = [[HyBidAdRequest alloc] init];
self.leaderboardAdRequest.adSize = HyBidAdSize.SIZE_728x90;
[self.leaderboardAdRequest requestAdWithDelegate:self withZoneID:<YOUR AD ZONE ID HERE>];
Request Ad from MoPub
After the ad is successfully received from PubNative, the request should be made to MoPub with some parameters that will help the ad be chosen properly in the MoPub waterfall.
The HyBidHeaderBiddingUtils must be used so that the SDK can generate the proper keywords for the received ad.
extension ViewController : HyBidAdRequestDelegate
{
func requestDidStart(_ request: HyBidAdRequest!)
{
print("Request\(request) started")
}
func request(_ request: HyBidAdRequest!, didLoadWith ad: HyBidAd!)
{
print("Request loaded with ad: \(ad)")
if (request == self.leaderboardAdRequest) {
self.moPubLeaderboard.keywords = HyBidHeaderBiddingUtils.createHeaderBiddingKeywordsString(with: ad, with: TWO_DECIMAL_PLACES)
self.moPubLeaderboard.loadAd()
}
}
func request(_ request: HyBidAdRequest!, didFailWithError error: Error!)
{
print("Request\(request) failed with error: \(error.localizedDescription)")
self.moPubLeaderboard.loadAd()
}
}
#pragma mark - HyBidAdRequestDelegate
- (void)requestDidStart:(HyBidAdRequest *)request
{
NSLog(@"Request %@ started:",request);
}
- (void)request:(HyBidAdRequest *)request didLoadWithAd:(HyBidAd *)ad
{
NSLog(@"Request loaded with ad: %@",ad);
if (request == self.leaderboardAdRequest) {
[self.moPubLeaderboard setKeywords:[HyBidHeaderBiddingUtils createHeaderBiddingKeywordsStringWithAd:ad withKeywordMode:TWO_DECIMAL_PLACES]];
[self.moPubLeaderboard loadAd];
}
}
- (void)request:(HyBidAdRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Request %@ failed with error: %@",request,error.localizedDescription);
[self.moPubLeaderboard loadAd];
}
After making this request to MoPub, it will run its waterfall and if the line item targeted by our keywords gets chosen, the HyBidMoPubHeaderBiddingLeaderboardCustomEvent adapter will be called to render the ad.
