VK Ads - advertising on VK projects in a new way
Home
News
Education
Insights
Events
Online courses
Certification
Case studies
Upvote
Monetization
Загружается...
Help Center
Registration
Help Center
Log-in
Creating and logging in to an account
Transfer campaigns and audiences
Transferring campaigns from myTarget
Transferring campaigns from VKontakte
Importing audiences from myTarget
Importing audiences from VKontakte
Connecting an account to an agency
For agencies: registration and import
Account overview
Multi-accounts
Connecting a VK ID
Deleting an account
Creating ads
How to create ads
Stages of creation
Ad limit
Statuses of campaigns, groups and ads
Editing campaigns, groups and ads
Copying campaigns, groups and ads
Deleting and restoring campaigns, groups and ads
Banner preview
Adding a redirect to the white list
Sites
Link markup for click verification
Site Advertising
VK Ads Pixel
Audience tags
Sending offline events to the pixel
Conversion attribution for websites
Visual constructor
Site Audience Portrait
Feed catalogs
Creating a catalog for a marketplace
Feed Advertising for sites and apps
Feed Advertising for VK Communities
Feed Advertising for marketplaces
Commercial Center (interface)
Commercial Center
Goods
Product Groups
Diagnostics
Events
History
Catalogs
Catalogs - what it is, how to create, edit and delete
General requirements for catalogs
Catalog for products according to Google specification
Catalog for products according to Yandex specification
Catalog for real estate
Catalog for real estate according to Yandex specifications
Catalog for transport
Catalog for transport according to Yandex specifications
Catalog for services
Catalogs for flights
Catalogs for flights (Google specification)
Catalogs for hotels
Catalogs for hotels (Google specification)
Catalog for medicinal products according to Yandex specification
Catalog for medicinal products according to Google specification
Dynamic retargeting
Dynamic retargeting based on mobile events
Dynamic retargeting based on web events
Deep links and tracking links in catalog product ads
Macros in catalog product ads
Apps
Mobile app Advertising
Adding new apps
Integration of the application with mobile tracker
Integrating apps with MyTracker
Integrating apps with AppMetrica
Integrating apps with AppsFlyer
AppsFlyer tracking link requirements
Integrating apps with Adjust
Integration apps with Branch
Integrating apps with Tenjin
Integrating apps with Singular
Integration of applications from Huawei AppGallery with trackers
Integration RuStore apps with trackers
Campaigns for RuStore apps – optimization by events
Seamless app install from RuStore
App cards
SKAdNetwork
Tracking link macros
Deep links in mobile app advertising
Promotion in social networks
Video and stream Advertising
Music Advertising
How to post content in VK Music
VK Mini Apps & VK Games Advertising
How to send events from a mini-app
Personal profile advertising
How to set up a personal profile before promotion
Promotion of groups and profiles in OK
Community
Community Advertising
Smart сampaigns
Dzen
Dzen advertising
Scroll-to-site
Tips for launching Dzen campaigns
Lead forms and surveys
Lead form Advertising
Survey form Advertising
YCLIENTS online form Advertising
Split-test for lead forms
Creating a landing page for lead form warmup
Media advertising
Launching media adverts
Banner Ads media format
Video Ads media format
VK Post media format
VK post, video or clip media format
Dzen media format
HTML5 banner
Group and profile OK
Direct deals
For agencies
Agency account guide
Agency clients
Agency managers
Agency work with ADO VK
Access rights
Ads settings
Ad formats
Text and title of the ad
Text generation
Macros in the headline and text of the ad
Old_version_24_10_24_Text creatives autogenerator
Images and video
Media library
Video generation
Image generation
Editing images: zoom in, improve quality, image refine
Smart image cropp
Images created by neural network
Budget optimization
Bid strategies
Auction
Targeting
Auto selection of targeting
Audiences and user lists
Audiences
User lists
Importing external audiences
Similar audiences (look-alike)
Expanding audience
Collecting audiences by reactions
UTM-tags
REF-tags
Placements
Change logs block
Hotkeys
Universal Link/App Link technology on site
API - VK Ads
Safe areas
Advertising objective
Statistics and Finance
Working with dashboard
Metrics and expanded statistics
Evaluating campaign effectiveness
Report upload
Folders in the campaign list
For agencies: Client statistics
Statistics from apps for web campaign
Billing and finances
For agencies: Account balance, payments, and closing documents
Bonuses and promo codes
Documents
Moderation Rules
Rules
Rules for Placing Advertisements
Legal documents
Rules for Placing Advertisements_26.03.2024
Publisher account
How to start monetizing
Connecting additional partner accounts
Setting up a publisher account
Partner account setup
Partner account notifications
Ad blocking
Getting strings for your ads.txt and app-ads.txt files
App placement
Start monetizing your app
Types of ad units for apps
Site placement
Start monetizing your website
Types of ad units for websites
Adaptive block: code creation and integration
InStream block: access and creation
InPage placements: code customization and integration
Flyroll mode for inPage blocks on sites
Recommendation widget
Ads on sites with CSP
Plugin for WordPress websites
Finger Print ID
Integration documentation
Web guides
Web integration for placement on pages
Web integration for placement within video
Header Bidding
Events and codes of Adman3 player
Android guides
Google Privacy & Security recommendations
Android integration guide
Banner Android
Native block Android
Fullscreen block Android
Rewarded video Android
Version history SDK Android
Adapters for other mediations Android
Test mode Android
iOS guides
iOS integration guide
Banner iOS
Native block iOS
Fullscreen block iOS
Rewarded video iOS
Version history SDK iOS
Adapters for other mediations iOS
Test mode iOS
Unity guides
Unity integration guide
Banner Unity
Fullscreen block Unity
Rewarded video Unity
Test mode Unity
ironSource mediation
MAX mediation
User Data
Integration Testing
Statistics in the publisher's account
Monetization stats
Publisher documents
Legal documents of the VK Ad Network
VK Ad Network publisher terms and conditions
Changes to partner details
Money withdrawal for residents
Money withdrawal for non-residents
Inventory moderation guide
Standard contractual clauses
Реквизиты компании для партнеров-резидентов
API VK Ad Network
Reporting API
Reporting API: Statistics
Management API
Help
Technical support
Direct deals
Direct deals for traffic providers
Direct deals marketplace
Creating and customizing a direct deals
Editing a transaction
Statistics and downloading of reports on transactions
Log-in
Creating and logging in to an account
Transfer campaigns and audiences
Transferring campaigns from myTarget
Transferring campaigns from VKontakte
Importing audiences from myTarget
Importing audiences from VKontakte
Connecting an account to an agency
For agencies: registration and import
Account overview
Multi-accounts
Connecting a VK ID
Deleting an account
Creating ads
How to create ads
Stages of creation
Ad limit
Statuses of campaigns, groups and ads
Editing campaigns, groups and ads
Copying campaigns, groups and ads
Deleting and restoring campaigns, groups and ads
Banner preview
Adding a redirect to the white list
Sites
Link markup for click verification
Site Advertising
VK Ads Pixel
Audience tags
Sending offline events to the pixel
Conversion attribution for websites
Visual constructor
Site Audience Portrait
Feed catalogs
Creating a catalog for a marketplace
Feed Advertising for sites and apps
Feed Advertising for VK Communities
Feed Advertising for marketplaces
Commercial Center (interface)
Commercial Center
Goods
Product Groups
Diagnostics
Events
History
Catalogs
Catalogs - what it is, how to create, edit and delete
General requirements for catalogs
Catalog for products according to Google specification
Catalog for products according to Yandex specification
Catalog for real estate
Catalog for real estate according to Yandex specifications
Catalog for transport
Catalog for transport according to Yandex specifications
Catalog for services
Catalogs for flights
Catalogs for flights (Google specification)
Catalogs for hotels
Catalogs for hotels (Google specification)
Catalog for medicinal products according to Yandex specification
Catalog for medicinal products according to Google specification
Dynamic retargeting
Dynamic retargeting based on mobile events
Dynamic retargeting based on web events
Deep links and tracking links in catalog product ads
Macros in catalog product ads
Apps
Mobile app Advertising
Adding new apps
Integration of the application with mobile tracker
Integrating apps with MyTracker
Integrating apps with AppMetrica
Integrating apps with AppsFlyer
AppsFlyer tracking link requirements
Integrating apps with Adjust
Integration apps with Branch
Integrating apps with Tenjin
Integrating apps with Singular
Integration of applications from Huawei AppGallery with trackers
Integration RuStore apps with trackers
Campaigns for RuStore apps – optimization by events
Seamless app install from RuStore
App cards
SKAdNetwork
Tracking link macros
Deep links in mobile app advertising
Promotion in social networks
Video and stream Advertising
Music Advertising
How to post content in VK Music
VK Mini Apps & VK Games Advertising
How to send events from a mini-app
Personal profile advertising
How to set up a personal profile before promotion
Promotion of groups and profiles in OK
Community
Community Advertising
Smart сampaigns
Dzen
Dzen advertising
Scroll-to-site
Tips for launching Dzen campaigns
Lead forms and surveys
Lead form Advertising
Survey form Advertising
YCLIENTS online form Advertising
Split-test for lead forms
Creating a landing page for lead form warmup
Media advertising
Launching media adverts
Banner Ads media format
Video Ads media format
VK Post media format
VK post, video or clip media format
Dzen media format
HTML5 banner
Group and profile OK
Direct deals
For agencies
Agency account guide
Agency clients
Agency managers
Agency work with ADO VK
Access rights
Ads settings
Ad formats
Text and title of the ad
Text generation
Macros in the headline and text of the ad
Old_version_24_10_24_Text creatives autogenerator
Images and video
Media library
Video generation
Image generation
Editing images: zoom in, improve quality, image refine
Smart image cropp
Images created by neural network
Budget optimization
Bid strategies
Auction
Targeting
Auto selection of targeting
Audiences and user lists
Audiences
User lists
Importing external audiences
Similar audiences (look-alike)
Expanding audience
Collecting audiences by reactions
UTM-tags
REF-tags
Placements
Change logs block
Hotkeys
Universal Link/App Link technology on site
API - VK Ads
Safe areas
Advertising objective
Statistics and Finance
Working with dashboard
Metrics and expanded statistics
Evaluating campaign effectiveness
Report upload
Folders in the campaign list
For agencies: Client statistics
Statistics from apps for web campaign
Billing and finances
For agencies: Account balance, payments, and closing documents
Bonuses and promo codes
Documents
Moderation Rules
Rules
Rules for Placing Advertisements
Legal documents
Rules for Placing Advertisements_26.03.2024
Publisher account
How to start monetizing
Connecting additional partner accounts
Setting up a publisher account
Partner account setup
Partner account notifications
Ad blocking
Getting strings for your ads.txt and app-ads.txt files
App placement
Start monetizing your app
Types of ad units for apps
Site placement
Start monetizing your website
Types of ad units for websites
Adaptive block: code creation and integration
InStream block: access and creation
InPage placements: code customization and integration
Flyroll mode for inPage blocks on sites
Recommendation widget
Ads on sites with CSP
Plugin for WordPress websites
Finger Print ID
Integration documentation
Web guides
Web integration for placement on pages
Web integration for placement within video
Header Bidding
Events and codes of Adman3 player
Android guides
Google Privacy & Security recommendations
Android integration guide
Banner Android
Native block Android
Fullscreen block Android
Rewarded video Android
Version history SDK Android
Adapters for other mediations Android
Test mode Android
iOS guides
iOS integration guide
Banner iOS
Native block iOS
Fullscreen block iOS
Rewarded video iOS
Version history SDK iOS
Adapters for other mediations iOS
Test mode iOS
Unity guides
Unity integration guide
Banner Unity
Fullscreen block Unity
Rewarded video Unity
Test mode Unity
ironSource mediation
MAX mediation
User Data
Integration Testing
Statistics in the publisher's account
Monetization stats
Publisher documents
Legal documents of the VK Ad Network
VK Ad Network publisher terms and conditions
Changes to partner details
Money withdrawal for residents
Money withdrawal for non-residents
Inventory moderation guide
Standard contractual clauses
Реквизиты компании для партнеров-резидентов
API VK Ad Network
Reporting API
Reporting API: Statistics
Management API
Help
Technical support
Direct deals
Direct deals for traffic providers
Direct deals marketplace
Creating and customizing a direct deals
Editing a transaction
Statistics and downloading of reports on transactions
VK Ads - advertising on VK projects in a new way
A platform for quickly launching effective advertising on VK projects. Allows you to interact with users of social networks, classifieds, media projects and advertising networks, turning them into your customers.
Registration
Sections
  • News
  • Insights
  • Case studies
  • Events
  • Help Center
  • Documents
  • Monetization
Contact us
international@vk.team
localization
en
About us
© 2025 VK
iOS guides

Native block iOS

  • Help
  • Publisher account
  • Integration documentation
  • iOS guides
Reading time 17 min

VK Ad SDK provides the ability to display ads in your app using native visual components. 

The SDK loads the ad and gives the app an ad model with specific properties and methods for counting impressions and handing clicks. 

The API also provides a build-in visual component that you can use in your app, instead of creating your own.

Initialization

To display native ads in your app, you must create an instance of the MTRGNativeAd class and specify your slotId.

@interface YourViewController : UIViewController
@end

@implementation YourViewController
{
 MTRGNativeAd *_ad;
}

- (void)initAd
{
   // Enabling debug mode
   // [MTRGManager setDebugMode:YES];
    
   // Create an instance of MTRGNativeAd
   _ad = [MTRGNativeAd nativeAdWithSlotId:YOUR_SLOT_ID];
}
 

Loading ads

To receive notifications (such as a successful data download or a download error, a click on an ad), you must set the created instance of MTRGNativeAd to a delegate that implements the MTRGNativeAdDelegate protocol, and then you can start the data download.

@interface YourViewController : UIViewController <MTRGNativeAdDelegate>
@end

@implementation YourViewController
{
 MTRGNativePromoAd *_ad;
}

- (void)initAd
{
   // Create an instance of MTRGNativeAd
   _ad = [MTRGNativeAd nativeAdWithSlotId:YOUR_SLOT_ID];
    
   // Set the delegate
   _ad.delegate = self;
    
   // Start loading ad
   [_ad load];
}
 
- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onNoAdWithReason:(NSString *)reason nativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onAdClickWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onShowModalWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onDismissModalWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 
- (void)onLeaveApplicationWithNativeAd:(MTRGNativeAd *)nativeAd
{
}

- (void)onVideoPlayWithNativeAd:(MTRGNativeAd *)nativeAd
{
}

- (void)onVideoPauseWithNativeAd:(MTRGNativeAd *)nativeAd
{
}

- (void)onVideoCompleteWithNativeAd:(MTRGNativeAd *)nativeAd
{
}
 

Media download policy

The loading policy specifies the behaviour of the SDK if it fails to load media files for advertisements. The policy is set in the bannerMediaRecovery property of instances of MTRGNativeAd and MTRGNativeAdLoader classes. Valid values are skip (default) and retry.

If MTRGNativeAd fails to load media files on autoload, then at:
 

  • skip, SDK will finish loading all adverts and call the onLoadFailedWithError:nativeAd delegate method:
  • retry, the SDK will retry loading the media a specified number of times. If the media files still fail to load, onLoadFailedWithError:nativeAd: will be called in the delegate.

If MTRGNativeAdLoader failed to load the media files in the banner on autoload, when:

  • skip, SDK will skip this banner. And it will not affect the loading of other banners loader.
  • retry, SDK will repeat loading media for this banner the specified number of times. If it still fails to load them, SDK will skip this banner.

The policy is also taken into account when autoloading is turned off, when media files are loaded asynchronously at the moment of registerView method call.

When autoloading is disabled, if MTRGNativeAd fails to load media files into registerView, then the:
 

  • skip, SDK will cancel media files that have not yet been downloaded and call the onMediaLoadFailedWithNativeAd: method of mediaDelegate.
  • retry, the SDK will retry loading the media files a specified number of times. If it still fails to load them, the onMediaLoadFailedWithNativeAd: method of mediaDelegate will be called.

In addition to the upload policy, it is also possible to set a timeout for media files to be uploaded. It is set in the bannerMediaTimeout property and applies to media files within the banner.

Autoloading images and video

By default, all media objects (images, videos) of the ad banner are loaded and cached. You can switch off automatic loading of images and/or videos, but you should take into account that it will take additional time to load them, which will create an additional delay in displaying ads in your application.

_ad.cachePolicy = MTRGCachePolicyNone;
[_ad load];

Valid values: MTRGCachePolicyAll (default), MTRGCachePolicyImages, MTRGCachePolicyVideo, MTRGCachePolicyNone.

If preloading is enabled, the corresponding media files (images and/or video) will be downloaded and stored in the cache in parallel with the loading of the main banner ad data.

If image preloading is disabled, images will be asynchronously loaded automatically when the registerView method is called. No additional actions are required.

Notifications about media files downloading

In order to receive notifications about media files downloading (in case of non-automatic downloading) it is necessary to implement the MTRGNativeAdMediaDelegate protocol and set the mediaDelegate property of the MTRGNativeAd object.

@protocol MTRGNativeAdMediaDelegate <NSObject>

- (void)onIconLoadWithNativeAd:(MTRGNativeAd *)nativeAd;

- (void)onImageLoadWithNativeAd:(MTRGNativeAd *)nativeAd;

- (void)onAdChoicesIconLoadWithNativeAd:(MTRGNativeAd *)nativeAd;

- (void)onMediaLoadFailedWithNativeAd:(MTRGNativeAd *)nativeAd;

@end

Ad Closing Notifications and Ad Closing Management

In order to receive ad closing notifications and manage ad closing it is necessary to set a delegate that implements the MTRGNativeAdChoicesOptionDelegate protocol in the adChoicesOptionDelegate property. The protocol contains several methods.

  • shouldCloseAutomatically - informs SDK whether to automatically close ads. If the method returns YES, the SDK will automatically hide the ads. If NO, the ability to hide is given to the developer. The method is optional and returns YES by default.
  • onCloseAutomatically - notifies the developer that the ad has been automatically hidden by the SDK. So this method will be called only if shouldCloseAutomatically returns YES.
  • closeIfAutomaticallyDisabled - notifies the developer that he needs to hide the ads himself. So this method will be called only if shouldCloseAutomatically returns NO.

Displaying ads

After successfully loading the ad, you can use the properties of the banner object to initialize your visual component. Which properties are available depends on what is being advertised, i.e. they differ for apps and websites.

To display icon image you should use MTRGIconAdView class. To display main image, carousel and video playback, you must use an instance of MTRGMediaAdView class from myTarget SDK.

myTargetSDK automatically detects if MTRGMediaAdView is contained within visual component and adds a horizontal cards slider (if cards exists in banner) or video (if there is no cards but video exists).

After initializing a visual component, use the registerView method to register it with the MTRGNativeAd instance. If you are going to use the same visual component to display other ads, you must first call the unregisterView method on the current MTRGNativeAd instance before calling registerView on another MTRGNativeAd instance. Impressions and clicks are processed automatically, and the application should not block or capture user touch events on this visual component. The properties available are described below, and examples of initializing visual components for different types of banners are given.

Visual components (built-in and custom) should be embedded into MTRGNativeAdContainer object.

You can pass either component itself or container when call method registerView.

When container created, visual component adView will be added as subview of container and will fit it's bounds.
In order to calculate height of visual component depending on it's width (required for TableView/CollectionView), you can call method sizeThatFits of container object.

When container created, you should setup bindings between properties of visual component (adView) and container's properties.

- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
   // Ad title
   NSString *title = promoBanner.title;
   // Main text
   NSString *descriptionText = promoBanner.descriptionText;
   // Age restriction. Can be nil
   NSString *ageRestrictions = promoBanner.ageRestrictions;
   // Disclaimer. Can be nil
   NSString *disclaimer = promoBanner.disclaimer;
   // "Advertising" label text
   NSString *advertisingLabel = promoBanner.advertisingLabel;
   // Icon
   MTRGImageData *icon = promoBanner.icon;
   // Call-to-action text for the button
   NSString *ctaText = promoBanner.ctaText;
   // Properties available only for ads promoting apps
   if (promoBanner.navigationType == MTRGNavigationTypeStore))
   {
       // App rating (0-5)
       NSNumber *rating = promoBanner.rating;
       // Number of votes
       NSUInteger votes = promoBanner.votes;
       // App category
       NSString *category = promoBanner.category;
       // App subcategory
       NSString *subcategory = promoBanner.subcategory;
   }
   // Properties available only for ads promoting websites
   else if (promoBanner.navigationType == MTRGNavigationTypeWeb)
   {
       // Website domain
       NSString *domain = promoBanner.domain;
   }
    
   // Example of filling a visual component
   UIView *adView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 300)];
   UILabel *titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 10, 200, 20)];
   titleLabel.text = title;
   UILabel *descLabel = [[UILabel alloc] initWithFrame:CGRectMake(70, 50, 200, 40)];
   descLabel.text = descriptionText;
   UIButton *ctaButton = [[UIButton alloc] initWithFrame:CGRectMake(210, 260, 80, 30)];
   [ctaButton setTitle:ctaText forState:UIControlStateNormal];
 
   // Create an instance of MTRGMediaAdView
   MTRGMediaAdView *mediaView = [MTRGNativeViewsFactory createMediaAdView];
   mediaView.frame = CGRectMake(10, 100, 280, 150);
   MTRGIconAdView *iconAdView = [MTRGNativeViewsFactory createIconAdView];
   iconAdView.frame = CGRectMake(10, 10, 50, 50);
    
   [adView addSubview:titleLabel];
   [adView addSubview:descLabel];
   [adView addSubview:iconAdView];
   [adView addSubview:mediaView];
   [adView addSubview:ctaButton];

   MTRGNativeAdContainer *containerView = [MTRGNativeAdContainer createWithAdView:adView];
   containerView.titleView = titleLabel;
   containerView.descriptionView = descLabel;
   containerView.iconView = iconAdView;
   containerView.mediaView = mediaView;
   containerView.ctaView = ctaButton;
    
   // Register the view
   [nativeAd registerView:containerView withController:self];
 
   // Add it to the screen
   [self.view addSubview:containerView];
}
 

Native ad assets

The library contains both mandatory and optional elements. The rules of ad placement require only mandatory elements to be displayed.

However, layouts with a full set of components are more clickable, so we recommend using them. 

Ad assetRequired
Advertising labelYes
Age restrictionsYes
DisclaimerYes
DomainYes
TitleYes
Menu iconYes
IconYes, for app ads
 Call-to-actionYes
MediaAdViewYes
DescriptionNo
RatingNo

Use a layout that displays the entire set of mandatory and optional ad components

Example of a native block for website advertising
Example of a native block for advertising mobile app
1 of 2
Example of a native block for website advertising

Setting size of MediaAdView

Aspect ratio of loaded image can be different to size of mediaView and you should adjust size using actual mediaAdView.aspectRatio value.

Notification about size change can be received using delegate onImageSizeChanged of object mediaAdView

mediaAdView.delegate = self;

- (void)onImageSizeChanged:(MTRGMediaAdView *)mediaAdView
{
   CGFloat currentAspect = mediaView.frame.size.width / mediaView.frame.size.height;
   NSLog(@"current aspect of media view: %f", currentAspect);
  
   CGFloat actualAspect = mediaView.aspectRatio;
   NSLog(@"actual aspect of media view: %f", actualAspect);
}
 

AdChoices icon

VK Ad SDK automatically adds an adChoices icon to each visual component. By default, the icon is added to the top-right corner of the visual component, but you can choose your preferred corner with the adChoicesPlacement property:

...
_ad.adChoicesPlacement = MTRGAdChoicesPlacementTopRight;
[_ad load];

Manual positioning of the AdChoices icon

To manually position the icon, set the adChoicesPlacement property to MTRGAdChoicesPlacementManual. Then, when configuring the visual component, you need to create an MTRGAdChoicesView and add it to the ad component. This way you can control the position and size of the adChoices icon, as well as set your own picture.

If no picture has been installed, the SDK will put its AdChoices icon in the MTRGAdChoicesView after you register the visual component in the ad object.

- (void)setupAdChoicesView
{
    _ad.adChoicesPlacement = MTRGAdChoicesPlacementManual;

   MTRGAdChoicesView *adChoicesView = MTRGNativeViewsFactory.createAdChoicesView;

   // Set your picture
   adChoicesView.imageView.image = [UIImage imageNamed:@"AdChoices"];

   [_adView addSubview:adChoicesView];

   // You can use Autolayout or frames to position and size adChoicesView
}
 

Manual rendering of the AdChoices icon

To fully control the AdChoices display component, you need to set adChoicesPlacement property to MTRGAdChoicesPlacementDrawingManual. Then the creation, content display, icon placement and click handling are completely up to the developers.

However, the SDK provides an AdChoices icon that you can use in your component (the "Auto-loading images and videos" and "Notification of successful uploading of Assets" items).

Get information about the presence of AdChoices (hasAdChoices property) and the icon (adChoicesIcon property) from MTRGNativePromoBanner.

To notify SDK that the AdChoices icon has been clicked, the handleAdChoicesClickWithController:sourceView: method must be called on the ad object.

- (void)setupAdChoicesView
{
   _ad.adChoicesPlacement = MTRGAdChoicesPlacementDrawingManual;

   _adChoicesButton = UIButton.new;
   [_adChoicesButton setImage:_ad.banner.adChoicesIcon.image forState:UIControlStateNormal];
   [_adChoicesButton addTarget:self action:@selector(adChoicesClick) forControlEvents:UIControlEventTouchUpInside];
   [_adView addSubview:_adChoicesButton];

   // You can use Autolayout or frames to position and size adChoicesImageView
}

// Notify SDK that the AdChoices component has been clicked
- (void)adChoicesClick
{
   [_ad handleAdChoicesClickWithController:self sourceView:_adChoicesButton];
}
 

Setting clickable area

In the example above, the visual component is registered using the registerView:withController method. In this case, the entire area of the visual component is clickable. MyTarget SDK provides the ability to register list of visual components that can be clicked. To do this, use the registerView:withController:withClickableViews method:

- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
   ...
   ...
   ...
    
   // Register the view with clickable titleView and button
   [nativeAd registerView:adView withController:self withClickableViews:@[titleLabel, ctaButton]];
 
   // Add it to the screen
   [self.view addSubview:adView];
}
 

Managing the display of the AdChoices menu

To control the display of AdChoices options, you need to pass an object that implements the MTRGMenuFactory protocol to the corresponding initializer. The protocol requires to implement a method to create a menu. The menu, on the other hand, must implement the MTRGMenu protocol. By default, the SDK uses the UIAlertController with the actionSheet style.

// Example of menu implementation

// Add MTRGMenuAction model to _items. An array of objects to be shown in the menu
- (void)addMenuAction:(nonnull MTRGMenuAction *)action
{
   [_items addObject:action];
}

// Based on _items, create a UIAlertController and display it
- (void)presentInViewController:(nonnull UIViewController *)viewController sourceView:(nullable UIView *)sourceView
{
   UIAlertControllerStyle style = UIAlertControllerStyleAlert;
   MTRGAlertController *alert = [MTRGAlertController alertControllerWithTitle:nil message:nil preferredStyle:style];

   for (MTRGMenuAction *item in _items.copy)
   {

       UIAlertActionStyle actionStyle = (item.style == MTRGMenuActionStyleDefault) ? UIAlertActionStyleDefault : UIAlertActionStyleCancel;

       UIAlertAction *action = [UIAlertAction actionWithTitle:item.title
                                                        style:actionStyle
                                                      handler:^(UIAlertAction * _Nonnull action)
                                {
           [item handleClick];
       }];
       [alert addAction:action];
   }

   [viewController presentViewController:alert animated:YES completion:nil];
}
 

Using built-in visual component

VK Ad SDK provides built-in visual component whose appearance you can customize to fit the design of your app.

We give an example below and describe the settings available.

MTRGNativeAdView

- (void)onLoadWithNativePromoBanner:(MTRGNativePromoBanner *)promoBanner nativeAd:(MTRGNativeAd *)nativeAd
{
   // Create an instance of MTRGNativeAdView
   MTRGNativeAdView *adView = [MTRGNativeViewsFactory createNativeAdView];
   adView.banner = promoBanner;
 
   // Available for customization internal views
   UILabel *titleLabel = adView.titleLabel;
   UILabel *descriptionLabel = adView.descriptionLabel;
   MTRGIconAdView *iconAdView = adView.iconAdView;
   MTRGMediaAdView *mediaView = adView.mediaAdView;
   UILabel *domainLabel = adView.domainLabel;
   UILabel *categoryLabel = adView.categoryLabel;
   UILabel *disclaimerLabel = adView.disclaimerLabel;
   MTRGStarsRatingView *ratingStarsView = adView.ratingStarsView;
   UILabel *votesLabel = adView.votesLabel;
   UIView *buttonView = adView.buttonView;
   UILabel *buttonToLabel = adView.buttonToLabel;
   UILabel *ageRestrictionsLabel = adView.ageRestrictionsLabel;
   UILabel *adLabel = adView.adLabel;
 
   // Margins
   UIEdgeInsets titleMargins = adView.titleMargins;
   UIEdgeInsets domainMargins = adView.domainMargins;
   UIEdgeInsets categoryMargins = adView.categoryMargins;
   UIEdgeInsets descriptionMargins = adView.descriptionMargins;
   UIEdgeInsets disclaimerMargins = adView.disclaimerMargins;
   UIEdgeInsets imageMargins = adView.imageMargins;
   UIEdgeInsets iconMargins = adView.iconMargins;
   UIEdgeInsets ratingStarsMargins = adView.ratingStarsMargins;
   UIEdgeInsets votesMargins = adView.votesMargins;
   UIEdgeInsets buttonMargins = adView.buttonMargins;
   UIEdgeInsets buttonCaptionMargins = adView.buttonCaptionMargins;
   UIEdgeInsets adLabelMargins = adView.adLabelMargins;
   UIEdgeInsets ageRestrictionsMargins = adView.ageRestrictionsMargins;   
 
   // Register the view
   [nativeAd registerView:adView withController:self];
    
   // Add it to the screen
   [self.view addSubview:adView];
}
 

Loading multiple banners

VK Ad SDK provides the MTRGNativeAdLoader class, which allows you to load from 1 to 20 banners with a single request. 

For MTRGNativeAdLoader, you can configure all the same settings that are available for configuration in MTRGNativeAd (for example, user gender and age settings, autoloading images and videos). 

VK Ad SDK does not guarantee that the number of banners specified in the COUNT parameter will be loaded - this parameter indicates the maximum number of banners you want to receive.

// Enable debug mode
// [MTRGManager setDebugMode:YES];


// Creating MTRGNativeAdLoader
MTRGNativeAdLoader *nativeAdLoader = [MTRGNativeAdLoader loaderForCount:COUNT slotId:YOUR_SLOT_ID];

// Loading banners
[nativeAdLoader loadWithCompletionBlock:^(NSArray<MTRGNativeAd *> * _Nonnull nativeAds)
{
   for (MTRGNativeAd *nativeAd in nativeAds)
   {
       // Installing the delegate
       nativeAd.delegate = self;
        
       MTRGNativePromoBanner *promoBanner = nativeAd.banner;
       // Code similar to protocol MTRGNativeAdDelegate method onLoadWithNativePromoBanner }
   }
}];
 

The resulting array will contain from 0 to COUNT MTRGNativeAd objects - each of them contains an already loaded MTRGNativePromoBanner and each of them must be treated in the same way as described in this documentation above, starting with calling the onLoadWithNativePromoBanner method.

Mediation with other advertising SDKs

Mediation with Mopub SDK is supported for native advertising.

Contents