iOS SDK: Banners

Initialization

To display 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. To specify the format, you must set one of MTRGAdSize values. The default format is 320x50.
@interface YourViewController : UIViewController
@end
 
@implementation YourViewController
{
  MTRGAdView *_adView;
}
 
- (void)initAd
{
    // Enabling debug mode
    // [MTRGAdView setDebugMode:YES]; 
     
    // Create an instance of MTRGAdView, 320x50 format
    _adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID];
  
    // Create an instance of MTRGAdView, 300x250 format
    // _adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID adSize:MTRGAdSize_300x250];
}

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;
 
    // Set the size
     _adView.frame = CGRectMake(0,0,320,50);
    // 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 isRefreshAd parameter when initializing the MTRGAdView instance. Rotation is only available for 320x50 and 728x90 formats.
// Disable automatic ad rotation
_adView = [MTRGAdView adViewWithSlotId:YOUR_SLOT_ID withRefreshAd:NO adSize:MTRGAdSize_320x50];
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?
Да
Нет