-
Notifications
You must be signed in to change notification settings - Fork 4
MoPub MRect Ads
MRect Ads will be rendered using MPAdView through the HyBidMoPubMRectCustomEvent adapter.
-
Ad Zone IDfrom the PubNative Publisher Dashboard -
MoPub Ad Unit IDfor the Ad Placement that you want to request.
- Declare a
MPAdView *moPubMrectproperty.
Swift:
var moPubMrect = MPAdView()Objective-C:
@property (nonatomic, strong) MPAdView *moPubMrect;- Instantiate the property that you have declared, passing in your
MoPub Ad Unit ID.
Swift:
self.moPubMrect = MPAdView (adUnitId: <YOUR MoPUB AD UNIT ID HERE>, size: MOPUB_MEDIUM_RECT_SIZE)Objective-C:
self.moPubMrect = [[MPAdView alloc] initWithAdUnitId:<YOUR MoPUB AD UNIT ID HERE>
size:MOPUB_MEDIUM_RECT_SIZE];- Register your view controller as the
moPubMrect's delegate (MPAdViewDelegate).
Swift:
self.moPubMrect.delegate = selfObjective-C:
self.moPubMrect.delegate = self;- Make sure to call
stopAutomaticallyRefreshingContentsmethod.
self.moPubMrect.stopAutomaticallyRefreshingContents()Objective-C:
[self.moPubMrect stopAutomaticallyRefreshingContents];- Implement the
MPAdViewDelegate'sviewControllerForPresentingModalViewmethod. Typically your controller can simply returnself.
Swift:
extension ViewController : MPAdViewDelegate
{
func viewControllerForPresentingModalView() -> UIViewController!
{
return self
}
}Objective-C:
#pragma mark - <MPAdViewDelegate>
- (UIViewController *)viewControllerForPresentingModalView
{
return self;
}For more information about MoPub MRect integration, you can refer to the MoPub Documentation as well.
- Import
HyBidinto your class.
Swift:
import HyBidObjective-C:
#import <HyBid/HyBid.h>- Declare a
HyBidMRectAdRequest *mRectAdRequestproperty.
Swift:
var mRectAdRequest = HyBidMRectAdRequest()Objective-C:
@property (nonatomic, strong) HyBidMRectAdRequest *mRectAdRequest;- Instantiate the property that you have declared. After this, you can request an Ad by, passing your
Ad Zone IDand also your registered view controller as themRectAdRequest's delegate (HyBidAdRequestDelegate).
Swift:
self.mRectAdRequest.requestAd(with: self, withZoneID: <YOUR AD ZONE ID HERE>)Objective-C:
self.mRectAdRequest = [[HyBidMRectAdRequest alloc] init];
[self.mRectAdRequest requestAdWithDelegate:self withZoneID:<YOUR AD ZONE ID HERE>];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 HyBidPrebidUtils must be used so that the SDK can generate the proper keywords for the received ad.
Swift:
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 == mRectAdRequest) {
self.moPubMrect.keywords = HyBidPrebidUtils.createPrebidKeywordsString(with: ad, with: TWO_DECIMAL_PLACES)
self.moPubMrect.loadAd()
}
}
func request(_ request: HyBidAdRequest!, didFailWithError error: Error!)
{
print("Request\(request) failed with error: \(error.localizedDescription)")
self.moPubMrect.loadAd()
}
}Objective-C:
#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.mRectAdRequest) {
[self.moPubMrect setKeywords:[HyBidPrebidUtils createPrebidKeywordsStringWithAd:ad withKeywordMode:TWO_DECIMAL_PLACES]];
[self.moPubMrect loadAd];
}
}
- (void)request:(HyBidAdRequest *)request didFailWithError:(NSError *)error
{
NSLog(@"Request %@ failed with error: %@",request,error.localizedDescription);
[self.moPubMrect loadAd];
}After making this request to MoPub, it will run its waterfall and if the line item targeted by our keywords gets chosen, the HyBidMoPubMRectCustomEvent adapter will be called to render the ad.