iOS SDK: Banners

Initialization

To display adaptive, 320x50, 300x250 and 728x90 banners in your app, you must create an instance of the MTRGAdView class. MTRGAdView is a visual component (subclass of UIView) that must be added to the app's screen.
The MTRGAdView's minimum size must be 320x50 pixels for 320x50 format, 300x250 pixels for 300x250 format and 728x90 pixels for 728x90 format. To create an instance of MTRGAdView, specify your slotId. You shouldn't set frame.size for MTRGAdView.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGAdView *_adView;
}
 
- (void)initAd
{
    // Enabling debug mode
    // [MTRGAdView setDebugMode:YES]; 
     
    // Create an instance of MTRGAdView, adaptive format
    _adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID];
  
    // 300x250 format
    // _adView.adSize = MTRGAdSizeType300x250;
}
By default MTRGAdSizeTypeAdaptive format will be used. In this case banner will be automatically resized by screen's width with respect to aspect ratio, height will become not less than 50 pixels, but not grater than 15% of screen's height.

There is an ability to redefine adSize property. Then SDK will discontinue observing device's orientation changes and stop adjusting banner's size. So in this case if you use adaptive size you should observe orientation changes:

- (void)viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    _adView.adSize = [MTRGAdSize adSizeForCurrentOrientation];
}
If load() method already called, you can't change format to 300x250 anymore (also can't set other format if 300x250 used before).

MTRGAdSize

MTRGAdSize - an object which allows you to define a size of MTRGAdView. Following sizes are available: MTRGAdSizeType320x50, MTRGAdSizeType300x250, MTRGAdSizeType728x90, MTRGAdSizeTypeAdaptive.
+ (instancetype)adSize320x50;
+ (instancetype)adSize300x250;
+ (instancetype)adSize728x90;
+ (instancetype)adSizeForCurrentOrientation; // Adaptive
+ (instancetype)adSizeForCurrentOrientationForWidth:(CGFloat)width; // Adaptive with maximum width restriction

Loading and displaying ads

The newly created and initialized MTRGAdView instance must be added to the app's screen. To handle clicks, you must set current ViewController on the MTRGAdView instance. To receive notifications (such as ad load succeeded, ad load failed, or ad clicked), you must set a delegate, which implements the MTRGAdViewDelegate protocol, on the MTRGAdView instance, and then start loading ad. After ad has loaded successfully, you can start displaying ad.
@interface YourViewController : UIViewController <MTRGAdViewDelegate>
@end
 
@implementation YourViewController
{
  MTRGAdView *_adView;
}
 
- (void)initAd
{
    // Create an instance of MTRGAdView
    _adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID];
     
    // Set the delegate
    _adView.delegate = self;
  
    // Set the controller
    _adView.viewController = self;
 
    // Add to display
    [self.view addSubview: _adView];
     
    // Start loading ad
    [_adView load];
}
  
- (void)onLoadWithAdView:(MTRGAdView *)adView
{
}
 
- (void)onNoAdWithReason:(NSString *)reason adView:(MTRGAdView *)adView
{
}
 
- (void)onAdShowWithAdView:(MTRGAdView *)adView
{
}
 
- (void)onAdClickWithAdView:(MTRGAdView *)adView
{
}
 
- (void)onShowModalWithAdView:(MTRGAdView *)adView
{
}
  
- (void)onDismissModalWithAdView:(MTRGAdView *)adView
{
}
  
- (void)onLeaveApplicationWithAdView:(MTRGAdView *)adView
{
}

Rotation

Ads are rotated every 60 seconds. You can disable automatic ad rotation by specifying the optional shouldRefreshAd parameter when initializing the MTRGAdView instance. Rotation is available for all banners except of 300x250 format.
// Disable automatic ad rotation
_adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID shouldRefreshAd:NO];
Banner 320x50

Mediation with other advertising SDKs

Mediation with Admob SDK or Mopub SDK is supported for banners. Automatic ad rotation is disabled during mediation.

Admob mediation

myTarget is a certified partner of Google Mediation.

Requirements
- Xcode 11 or higher
- iOS Deployment target of 9.0 or higher
- Google Mobile Ads SDK 7.57.0 or higher

Brief instruction for mediation myTarget via Admob
- Configure mediation settings for your Admob ad unit
- Import myTarget SDK and adapter (myTarget SDK and Google Mobile Ads SDK will e installed automatically in case if you use CocoaPods dependencies manager)
- Test integration

Please read full instruction here: https://developers.google.com/admob/ios/mediation/mytarget#step_2_configure_mediation_settings_for_your_ad_unit

Mopub mediation

Mediation with Mopub SDK requires adding following files to your project: https://github.com/myTargetSDK/mytarget-ios/tree/master/mediation/mopub

Mediation is configured at http://www.mopub.com/

To create a mediation network, go to the Networks section and add a Custom Native Network, specifying the following parameters:

Field
Value
CUSTOM EVENT CLASS
MTRGMopubAdViewCustomEvent
CUSTOM EVENT CLASS DATA
{"slotId":"<your slot Id>"}
Was this article helpful?
Yes
No