iOS SDK Integration - Mintegral

iOS开发文档

概要

本文档描述了iOS开发者如何集成Mintegral SDK产品,通过集成Mintegral SDK 展示广告创造收益
Mintegral SDK提供了8种广告形式,包括:Banner(横幅广告)、Native(原生广告)、NativeVideo(原生视频)、Auto Rending Native(自动渲染原生广告)、RewardVideo(激励性视频)、Interstitial(插屏)、Interstitial Video(插屏视频)、InterActive(试玩广告)、Splash(开屏广告)。

集成前准备

获取账号信息

App Key
登录Mintegral开发者后台,在APP Setting -> APP Key界面,可以查看到该账号的APP Key,如图所示:


APP ID
开发者每创建一个应用后,系统会自动生成App ID,可在APP Setting -> APP ID界面查看到已创建的应用以及对应的App ID,如图所示:


Placements & Units
开发者每创建一个广告版位后,系统会自动生成Placement ID,可在APP Setting -> Placement Management -> Edit Placement & Unit界面添加或修改该广告版位的Unit Id,如图所示:

虚拟货币概念

MTG平台为开发者提供管理部分虚拟货币的能力,使存在内部货币机制的产品可以运用自己的虚拟货币更好地激励用户。
后台增加“虚拟货币”管理模块,用于管理开发者的虚拟货币信息(Reward Info),Reward info设置信息可以与各种奖励性广告类型Placement ID进行同步,方便开发者管理自己的虚拟货币。

创建虚拟货币

在后台右侧菜单栏中找到虚拟货币,进行创建。

新建货币类型

配置虚拟货币
在Placement下配置虚拟货币

开发环境

开发工具:
MTGSDK 从6.3.3版本开始不再支持XCode11以下版本archive

获取SDK

我们提供两种方式去集成Mintegral iOS-SDK:使用Cocoapods手动添加方式

关于SDK的文件大小:
SDK基础公共包,增加2.2M 左右
集成全部广告样式,最大增加0.3M 左右,共2.5M

获取SDK版本号

搜索MTGSDK.h文件,找到MTGSDKVersion

iOS 14 指引

MTGSDK 6.6.0 版本提供了对 iOS SKAdNetwork 的支持。
为您的应用适配iOS14,请按照以下步骤集成:

1、升级 MTGSDK 至 6.6.0 或以上版本。
2、将 MTGSDK 的 SKAdNetwork ID 添加到 info.plist 中。

SKAdNetwork IDs

SKAdNetwork 是 Apple 针对iOS 14 的归因解决方案,可在保护用户隐私的同时完成广告归因。 使用 SKAdNetwork 后,即使 IDFA 不可用,也可以正确获得应用安装的归因结果。 您可以访问 SKAdNetwork 了解更多信息。

添加SKAdNetwork ID到Info.plist

MTGSDK SKAdNetwork ID

<key>SKAdNetworkItems</key>
<array>
    <dict>
      <key>SKAdNetworkIdentifier</key>
      <string>KBD757YWX3.skadnetwork</string>
    </dict>
</array>

合作伙伴的 SKAdNetwork ID

<key>SKAdNetworkItems</key>
<array>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>wg4vff78zm.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>737z793b9f.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>ydx93a7ass.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>prcb7njmu6.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>7UG5ZH24HU.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>44jx6755aq.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>2U9PT9HC89.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>W9Q455WK68.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>YCLNXRL5PM.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>TL55SBB4FM.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>8s468mfl3y.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>GLQZH8VGBY.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>c6k4g5qg8m.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>mlmmfzh3r3.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>4PFYVQ9L8R.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>av6w8kgt66.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>6xzpu9s2p8.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>hs6bdukanm.skadnetwork</string>
    </dict>
    <dict>
        <key>SKAdNetworkIdentifier</key>
        <string>v72qych5uu.skadnetwork</string>
    </dict>
</array>

SDK的初始化

作为集成的第一步,你需要先将Mintegral的SDK进行初始化。

手动集成需做的初始化前的参数配置

1、手动集成需导入基本的静态库

CoreGraphics.framework
Foundation.framework
UIKit.framework
libsqlite3.tbd (在Xccode7以下是libsqlite3.dylib)
libz.tbd (在Xcode7以下是libz.dylib)
AdSupport.framework
StoreKit.framework
QuartzCore.framework
CoreTelephony.framework
MobileCoreServices.framework
AVFoundation.framework
WebKit.framework

2、增加XCode的链接器参数

在工程的Build Settings中,找到Other Linker Flags,增加一个flag:-ObjC,注意大小写。

初始化

在AppDelegate里的如下方法中调用MTGSDK的初始化方法,传入在Mintergal后台得到的AppID和AppKey。初始化时,MTGSDK会从服务器拉取配置信息。建议在主线程调用此方法。

//tips:ApiKey and AppKey are the same.
- (void)setAppID:(nonnull NSString *)appID ApiKey:(nonnull NSString *)appKey;

示例代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
    [[MTGSDK sharedInstance] setAppID:@"your appID" ApiKey:@"your appKey"];
}

横幅广告接入

横幅广告是在应用布局中占据一处位置的矩形图片文字广告。用户与应用互动时,这类广告会停留在屏幕上,并且可在一段时间后自动刷新。

广告效果示意:

导入头文件

#import <MTGSDK/MTGSDK.h>
#import <MTGSDKBanner/MTGBannerAdView.h>
#import <MTGSDKBanner/MTGBannerAdViewDelegate.h>

初始化MTGBannerAdView

/**
 This is a method to initialize an MTGBannerAdView with the given unit id

 @param adSize The size of the banner view.
 @param placementId The id of the ad placement id. You can create your ad placement from our Portal.
 @param unitId The id of the ad unit. You can create your unit id from our Portal.
 @param rootViewController The view controller that will be used to present full screen ads.
 @return
 */
- (nonnull instancetype)initBannerAdViewWithAdSize:(CGSize)adSize
                                       placementId:(nullable NSString *)placementId
                                            unitId:(nonnull NSString *) unitId
                                rootViewController:(nullable UIViewController *)rootViewController;

/**
 This is a method to initialize an MTGBannerAdView with the given unit id

 @param bannerSizeType please refer to enum MTGBannerSizeType.
 @param placementId The id of the ad placement id. You can create your ad placement from our Portal.
 @param unitId The id of the ad unit. You can create your unit id from our Portal.
 @param rootViewController The view controller that will be used to present full screen ads.
 @return
 */
- (nonnull instancetype)initBannerAdViewWithBannerSizeType:(MTGBannerSizeType)bannerSizeType
                                               placementId:(nullable NSString *)placementId
                                                    unitId:(nonnull NSString *) unitId
                                        rootViewController:(nullable UIViewController *)rootViewController;

bannerSizeType 介绍:
我们建议使用320*50,该尺寸的填充率会更能得到保障,调整尺寸可能一定程度影响收入。

typedef NS_ENUM(NSInteger,MTGBannerSizeType) {
    /*Represents the fixed banner ad size - 320pt by 50pt.*/
    MTGStandardBannerType320x50,

    /*Represents the fixed banner ad size - 320pt by 90pt.*/
    MTGLargeBannerType320x90,

    /*Represents the fixed banner ad size - 300pt by 250pt.*/
    MTGMediumRectangularBanner300x250,

    /*if device height <=720,Represents the fixed banner ad size - 320pt by 50pt;
      if device height > 720,Represents the fixed banner ad size - 728pt by 90pt*/
    MTGSmartBannerType
};

请求广告

- (void)loadBannerAd;

销毁BannerAdView

/**
 This method will clear all the variables and properties of the MTGBannerAdView.

 NOTE: After calling this method, if you need to continue using the MTGBannerAdView, you must reinitialize a MTGBannerAdView
 */
- (void)destroyBannerAdView;

其他功能API介绍

/**
 Automatic refresh time, in seconds, is set in the range of 10s~180s.
 If set to 0, it will not be automatically refreshed.
 You need to set it before loading ad.
 */
@property(nonatomic,assign) NSInteger autoRefreshTime;

/**
 Whether to show the close button
 MTGBoolNo means off,MTGBoolYes means on
 defalut MTGBoolUnknown
 */
@property(nonatomic,assign) MTGBool showCloseButton;

/**
* get the id of this request ad,call  after adViewLoadSuccess
*/
@property(nonatomic,copy,readonly) NSString * _Nullable requestId;

示例代码

#import "TestViewController.h"
#import <MTGSDK/MTGSDK.h>
#import <MTGSDKBanner/MTGBannerAdView.h>
#import <MTGSDKBanner/MTGBannerAdViewDelegate.h>
@interface TestViewController ()<MTGBannerAdViewDelegate>

@property (nonatomic, strong) MTGBannerAdView *bannerAdView;

@end

@implementation TestViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    if (_bannerAdView == nil) {
        _bannerAdView = [[MTGBannerAdView alloc]initBannerAdViewWithAdSize:size placementId:kBannerPlacementId unitId:kBannerUnitID rootViewController:self];
    _bannerAdView.frame = CGRectMake(10, 100, size.width,size.height);
    _bannerAdView.delegate = self;

        _bannerAdView.autoRefreshTime = 0;//Automatic refresh time, in seconds, is set in the range of 10s~180s.If set to 0, it will not be automatically refreshed.

        _bannerAdView.delegate = self;
        [self.view addSubview:_bannerAdView];
        [_bannerAdView loadBannerAd];

    }

}

- (IBAction)destroyButtonAction:(id)sender
{
   [_bannerAdView destroyBannerAdView];
}

#pragma mark MTGBannerAdViewDelegate
- (void)adViewLoadSuccess:(MTGBannerAdView *)adView
{
        //This method is called when adView ad slot loaded successfully.
    [self log:@"adViewLoadSuccess"];
}

- (void)adViewLoadFailedWithError:(NSError *)error adView:(MTGBannerAdView *)adView
{
    //This method is called when adView ad slot failed to load.
    [self log:[NSString stringWithFormat:@"Failed to load ads, error:%@", error.localizedDescription]];
}

- (void)adViewWillLogImpression:(MTGBannerAdView *)adView
{
    //This method is called before the impression of an MTGBannerAdView object.
    [self log:@"adViewWillLogImpression"];
}

- (void)adViewDidClicked:(MTGBannerAdView *)adView
{
    //This method is called when ad is clicked.
    [self log:@"adViewDidClicked"];
}

- (void)adViewWillLeaveApplication:(MTGBannerAdView *)adView
{
    //Sent when a user is about to leave your application as a result of tapping.Your application will be moved to the background shortly after this method is called.
    [self log:@"adViewWillLeaveApplication"];
}
- (void)adViewWillOpenFullScreen:(MTGBannerAdView *)adView
{
    //Would open the full screen view.Sent when openning storekit or openning the webpage in app.
    [self log:@"adViewWillOpenFullScreen"];
}
- (void)adViewCloseFullScreen:(MTGBannerAdView *)adView
{
    //Would close the full screen view.Sent when closing storekit or closing the webpage in app.
    [self log:@"adViewCloseFullScreen"];
}

@end

原生(视频)广告接入

原生广告是时下非常流行的广告类型之一,广告SDK会将素材信息返回给您的app,您可以根据需要对元素进行组装和渲染,进而使得广告内容更贴近您的产品风格,用户体验更好。

注:该广告类型仅对部分开发者提供,如有需要请联系您的AM 或 致信developer@mintegral.com

广告效果示意:

导入头文件

#import <MTGSDK/MTGSDK.h>

初始化MTGNativeAdManager

/*

 Initialize the native ads manager which is for loading ads. (MTGCampaign)

 @param unitId The id of the ad unit. You can create your unit id from our Portal.
 @param fbPlacementId The Facebook PlacementID is used to request ads from Facebook. You can also set the placementID in our portal. The ID you set in our web portal will replace the ID you set here in future.
 @param videoSupport DEPRECATED_ATTRIBUTE Mintegral support configuration: https://www.mintegral.net
 @param numAdsRequested The number of ads you would like the native ad manager to retrieve. Max number is 10. If you pass any number bigger than 10, it will be reset to 10.
 @param viewController The UIViewController that will be used to present SKStoreProductViewController
 (iTunes Store product information) or the in-app browser. If not set, it will be the root viewController of your current UIWindow. But it may failed to present our view controller if your rootViewController is presenting other view controller. So set this property is necessary.
 */
- (nonnull instancetype)initWithPlacementId:(nullable NSString *)placementId
                                     unitID:(nonnull NSString *)unitId
                              fbPlacementId:(nullable NSString *)fbPlacementId
                               videoSupport:(BOOL)videoSupport
                         forNumAdsRequested:(NSUInteger)numAdsRequested
                   presentingViewController:(nullable UIViewController *)viewController;

示例代码:

[[MTGNativeAdManager alloc] initWithPlacementId:KNativeUnitID unitID:KNativeUnitID fbPlacementId:KPlacementID videoSupport:YES forNumAdsRequested:1 presentingViewController:self];

预加载广告(强烈建议)

我们对Native(NativeVideo)广告形式提供预加载功能(可选),可以在初始化环节调用以下代码进行预加载,提高你的广告加载效率。示例代码如下:

/**
 *
 @method

 @abstract The method that kicks off the preloading of native ads. It may be called again in the future to refresh the ads manually.

 @param placementId The id of the ad placement. You can create your placement id from our Portal.
 @param unitId The id of the ad unit. You can create your unit id from our Portal.

 @param fbPlacementId The Facebook PlacementID is used to request ads from Facebook. You can also set the placementID in our portal. The ID you set in our web portal will replace the ID you set here in future.

 @param videoSupport If the support video ads, set videoSupport  to yes.

 @param numAdsRequested The number of ads you would like to preload. Max number is 10. If you pass any number bigger than 10, it will be reset to 10.
 */
- (void)preloadNativeAdsWithPlacementId:(nullable NSString *)placementId
                                 unitId:(nonnull NSString *)unitId
                          fbPlacementId:(nullable NSString *)fbPlacementId
                           videoSupport:(BOOL)videoSupport
                     forNumAdsRequested:(NSUInteger)numAdsRequested;

请求广告

Mintegral SDK调用此方法时会优先从缓存里读取广告,如果缓存里有广告,则直接返回,进而提升展示效率;如果缓存里没有,则会向服务器发送广告请求获取广告。 请求方法如下:

- (void)loadAds;

渲染广告

您可以根据nativeAdsLoaded的回调去渲染广告,同时我们提供MTGMediaView去展示图片(视频)广告,调用以下方法去展示广告。MTGMediaView的最佳设置展示比例大小为16:9。

- (void)setMediaSourceWithCampaign:(MTGCampaign *)campaign unitId:(NSString*)unitId;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/**
* get the id of this request ad,call  after nativeAdsLoaded.
*/
@property (nonatomic, readonly) NSString *_Nullable requestId;

Adchoice标记

我们提供MTGAdChoicesView来渲染广告标记(Adchoice)。对其两个属性进行赋值即可完成广告标记。

Tip:我们强烈建议开发者规划合适位置展示此图标,若未展示,会影响您后续的广告收益。

/**
 Initialize this view with a given frame.

 @param frame For best user experience, keep the size of this view the same as AdChoiceIcon's, which can be pulled from MTGCampaign's -adChoiceIconSize
 */
- (instancetype)initWithFrame:(CGRect)frame;

/**
 The campaign obj that provides AdChoices info, such as the image url, and click url.
 */
@property (nonatomic, weak, readwrite, nullable) MTGCampaign *campaign;

对view设置广告点击跳转事件

- (void)registerViewForInteraction:(UIView *)view withViewController:(UIViewController *)viewController withClickableViews:(NSArray *)clickableViews;
- (void)registerViewForInteraction:(UIView *)view withViewController:(UIViewController *)controller;

MTGMediaView一些功能API介绍

#import <UIKit/UIKit.h>
#import "MTGCampaign.h"
NS_ASSUME_NONNULL_BEGIN

@protocol MTGMediaViewDelegate;
@class MTGNativeAdManager;

@interface MTGMediaView : UIView

/* For best user experience, keep the aspect ratio of the mediaView at 16:9 */
- (instancetype)initWithFrame:(CGRect)frame;
/**
the media source, can be set again to reuse this view.
*/
- (void)setMediaSourceWithCampaign:(MTGCampaign *)campaign unitId:(NSString*)unitId;

@property (nonatomic, weak, nullable) id<MTGMediaViewDelegate> delegate;

// Whether to allow full-screen playback, default YES
@property (nonatomic, assign) BOOL  allowFullscreen;

// Whether update to video from static image when video is ready to be played, default YES
@property (nonatomic, assign) BOOL  videoRefresh;

// Auto replay, default YES
@property (nonatomic, assign) BOOL  autoLoopPlay;
/* show video process view or not. Default to be YES. */
@property (nonatomic, assign) BOOL  showVideoProcessView;
/* show sound indicator view or not. Default to be YES. */
@property (nonatomic, assign) BOOL  showSoundIndicatorView;
/* mute audio output of the video player or not. Default to be YES, means video player is muted. */
@property (nonatomic, assign) BOOL mute;

@property (nonatomic, strong, readonly) MTGCampaign *campaign;

@property (nonatomic, readonly) NSString *unitId;

/**
 After called 'setMediaSourceWithCampaign:(MTGCampaign *)campaign unitId:(NSString*)unitId',
 you can check this MediaView whether has video content via isVideoContent if needed;
 */
@property (nonatomic,readonly,getter = isVideoContent) BOOL videoContent;

@end

@protocol MTGMediaViewDelegate <NSObject>

@optional

/*!
 @method

 @abstract
 Sent just before an MTGMediaView will enter the fullscreen layout.

 @param mediaView: An mediaView object sending the message.
 */
- (void)MTGMediaViewWillEnterFullscreen:(MTGMediaView *)mediaView;

/*!
 @method

 @abstract
 Sent after an FBMediaView has exited the fullscreen layout.

 @param mediaView: An mediaView object sending the message.
 */
- (void)MTGMediaViewDidExitFullscreen:(MTGMediaView *)mediaView;

/**
 *  Called when the native video was starting to play.
 *
 *  @param mediaView: An mediaView object sending the message.
 */
- (void)MTGMediaViewVideoDidStart:(MTGMediaView *)mediaView;

/**
*  Called when  the video play completed.
*
*  @param mediaView: An mediaView object sending the message.
*/
- (void)MTGMediaViewVideoPlayCompleted:(MTGMediaView *)mediaView;

/*!
 @method

 @abstract
 Sent after an ad has been clicked by a user.

 @param nativeAd An MTGCampaign object sending the message.
 */
- (void)nativeAdDidClick:(nonnull MTGCampaign *)nativeAd;
- (void)nativeAdDidClick:(nonnull MTGCampaign *)nativeAd mediaView:(MTGMediaView *)mediaView;

/*!
 @method

 @abstract
 Sent after an ad url did start to resolve.

 @param clickUrl The click url of the ad.
 */
- (void)nativeAdClickUrlWillStartToJump:(nonnull NSURL *)clickUrl;
- (void)nativeAdClickUrlWillStartToJump:(nonnull NSURL *)clickUrl mediaView:(MTGMediaView *)mediaView;

/*!
 @method

 @abstract
 Sent after an ad url has jumped to a new url.

 @param jumpUrl The url during jumping.

 @discussion It will not be called if a ad's final jump url has been cached
 */
- (void)nativeAdClickUrlDidJumpToUrl:(nonnull NSURL *)jumpUrl;
- (void)nativeAdClickUrlDidJumpToUrl:(nonnull NSURL *)jumpUrl  mediaView:(MTGMediaView *)mediaView;

/*!
 @method

 @abstract
 Sent after an ad url did reach the final jump url.

 @param finalUrl the final jump url of the click url.
 @param error the error generated between jumping.
 */
- (void)nativeAdClickUrlDidEndJump:(nullable NSURL *)finalUrl
                             error:(nullable NSError *)error;
- (void)nativeAdClickUrlDidEndJump:(nullable NSURL *)finalUrl
                             error:(nullable NSError *)error  mediaView:(MTGMediaView *)mediaView;

- (void)nativeAdImpressionWithType:(MTGAdSourceType)type mediaView:(MTGMediaView *)mediaView;

@end

示例代码

#import "TestViewController.h"
#import <MTGSDK/MTGSDK.h>
#import <MTGSDK/MTGNativeAdManager.h>
@interface TestViewController ()<MTGNativeAdManagerDelegate,MTGMediaViewDelegate>

@property (nonatomic, strong) MTGNativeAdManager *nativeVideoAdManager;
@property (weak, nonatomic) IBOutlet MTGMediaView *mMediaView;
@property (weak, nonatomic) IBOutlet UIImageView *iconImageView;
@property (weak, nonatomic) IBOutlet UILabel *appNameLabel;
@property (weak, nonatomic) IBOutlet UILabel *appDescLabel;
@property (weak, nonatomic) IBOutlet UIButton *adCallButton;
@property (weak, nonatomic) IBOutlet MTGAdChoicesView *adChoicesView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adChoicesViewWithConstraint;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *adChoicesViewHeightConstraint;

@end

@implementation TestViewController

//Init MTGNativeAdManager
- (IBAction)initAdManagerButtonAction:(id)sender
{
    //clean old demo view
    [self cleanAllDemoView];
    if (self.currentStyleIndex == 0) {
        _nativeAdManager1 = [[MTGNativeAdManager alloc] initWithPlacementId:KNativePlacementId unitID:KNativeUnitID fbPlacementId:KPlacementID supportedTemplates:@[[MTGTemplate templateWithType:MTGAD_TEMPLATE_BIG_IMAGE adsNum:1]] autoCacheImage:NO adCategory:0 presentingViewController:self];
        _nativeAdManager1.showLoadingView = YES;

        _nativeAdManager1.delegate = self;
    }
    else if (self.currentStyleIndex == 1){
        _nativeAdManager2 = [[MTGNativeAdManager alloc] initWithPlacementId:PlacementId unitID:KNativeUnitID fbPlacementId:KPlacementID videoSupport:NO forNumAdsRequested:1 presentingViewController:self];

        _nativeAdManager3.delegate = self;
    }

    [self log:@"MTGNativeAdManager init"];
}

#pragma mark AdManger delegate
- (void)nativeAdsLoaded:(NSArray *)nativeAds nativeManager:(nonnull MTGNativeAdManager *)nativeManager
{

    if (nativeAds.count > 0) {
        MTGCampaign *campaign=nativeAds[0];
        self.mMediaView.delegate = self;
        //Set the camgaign fot the MTGmediaview
        [self.mMediaView setMediaSourceWithCampaign:campaign unitId:@"your unitid"];
        self.appNameLabel.text = campaign.appName;
        self.appDescLabel.text = campaign.appDesc;
        [self.adCallButton setTitle:campaign.adCall forState:UIControlStateNormal];
        [campaign loadIconUrlAsyncWithBlock:^(UIImage *image) {
        if (image) {
                [self.iconImageView setImage:image];
            }
        }];
        // Set the MTGAdchoiceview with frame and campaign
        if (CGSizeEqualToSize(campaign.adChoiceIconSize, CGSizeZero)) { // Suggest to hide the adChoicesView when the campaign.adChoiceIconSize equals to zero
        self.adChoicesView.hidden = YES;
    } 
        else {
        self.adChoicesView.hidden = NO;
        // Suggest to set the adChoicesView'size depends on  campaign.adChoiceIconSize
        self.adChoicesViewWithConstraint.constant = campaign.adChoiceIconSize.width;
        self.adChoicesViewHeightConstraint.constant = campaign.adChoiceIconSize.height;
    }    
        self.adChoicesView.campaign = campaign;
        [ self.nativeVideoAdManager registerViewForInteraction:self.appDescLabel.text withCampaign:campaign];

    }

}

- (void)nativeAdsFailedToLoadWithError:(NSError *)error nativeManager:(nonnull MTGNativeAdManager *)nativeManager
{
    [self log:[NSString stringWithFormat:@"Failed to load ads, error:%@", error.localizedDescription]];
}

- (void)nativeAdImpressionWithType:(MTGAdSourceType)type nativeManager:(MTGNativeAdManager *)nativeManager
{

}

#pragma mark MediaView delegate
- (void)MTGMediaViewWillEnterFullscreen:(MTGMediaView *)mediaView{
    [self log:@"MTGMedia View Will Enter Full Screen"];
}

- (void)MTGMediaViewDidExitFullscreen:(MTGMediaView *)mediaView{
    [self log:@"MTGMedia View Did Exit Full Screen"];
}

#pragma mark MediaView and AdManger Click delegate
- (void)nativeAdDidClick:(MTGCampaign *)nativeAd
{
    [self log:@"Registerview or mediaVie Ad is clicked"];
}

- (void)nativeAdDidClick:(MTGCampaign *)nativeAd nativeManager:(nonnull MTGNativeAdManager *)nativeManager
{
    [self log:@"Registerview Ad is clicked"];
}
- (void)nativeAdDidClick:(MTGCampaign *)nativeAd mediaView:(nonnull MTGMediaView *)mediaView
{
    [self log:@"MTGMediaView Ad is clicked"];
}

- (void)MTGMediaViewVideoPlayCompleted:(MTGMediaView *)mediaView {
    [self log:NSStringFromSelector(_cmd)];
}

@end

自动渲染原生广告

自动渲染原生广告集成比普通原生广告更加简单,开发者只需提供宽高区域,MTG会自动展示与之契合的广告模板和素材。减少开发者对接成本的同时,更高效地利用MTG算法输出广告创意,进而提升开发者收入水平。

广告效果示意:

导入头文件

#import "MTGNativeAdvancedAd.h"

MTGNativeAdvancedAd 初始化

/**
This is a method to initialize.

@param adSize The nativeAdvanced ad size.We recommend that your size is set to 320 * 250.
@param placementId The id of the ad placement id. You can create your ad placement from the portal of mintegral.
@param unitId The id of the ad unit. You can create your unit id from the portal of mintegral.
@param rootViewController The view controller that will be used to present full screen ads.
@return
*/
- (nonnull instancetype)initWithPlacementID:(nullable NSString *)placementID
                                 unitID:(nonnull NSString *)unitID
                                 adSize:(CGSize)adSize
                     rootViewController:(nullable UIViewController *)rootViewController NS_DESIGNATED_INITIALIZER;

可设置项

设置Style
可设置的target有title、subTitle、button、icon、container、mediaContent.
如图:

/**
 This is a method to decorate the elements for the ad content.

 @param style  The setting for the elements of the ad content.
 @param target you can set title、subTitle、button、icon、container、mediaContent.
 @param values you can set background Color,font Size,font Family,Color and padding of the view.

 For example:

     NSDictionary *styles = @{
        @"list": @[
                @{
                    // 目标元素
                    @"target": @"container",
                    // 样式值
                    @"values": @{

                            @"paddingTop": @(0),
                            @"paddingRight": @(0),
                            @"paddingBottom": @(0),
                            @"paddingLeft": @(0),

                            @"backgroundColor": @"#FC2E02",
                            @"fontSize": @(20),
                            @"color": @"#060602",
                            @"fontFamily": @"Apple Symbols"
                    }

                }
            ]
    };

*/
- (void)setAdElementsStyle:(NSDictionary *)style;

静音设置

/**
 Whether or not to mute the video player.
 You should set YES if you want to mute the video player, otherwise NO.
*/
@property(nonatomic,assign) BOOL mute;

自动化播放设置

/** The type to control ad video play. */
@property(nonatomic,assign) MTGNativeAdvancedAdVideoPlayType autoPlay;

关闭按钮设置

/**
 Whether or not to show the close button.
 You should set YES if you want to show the close button, otherwise NO.
*/
@property(nonatomic,assign) BOOL showCloseButton;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/**
* get the id of this request ad,call  after nativeAdvancedAdLoadSuccess.
*/
@property(nonatomic,copy,readonly) NSString *_Nullable requestId;

加载广告

/**
 Request a NativeAdvanced Ad.
*/
- (void)loadAd;

判断是否加载完成

/**
 Whether or not if there was a available ad to show.

 @return YES means there was a available ad, otherwise NO.
*/
- (BOOL)isAdReady;

展示广告

/**
 Fetch the adView

 @note If get the adView before loadSuccess, you will get a UIView without a ad, which will be  attached a ad after loadSuccess
*/
- (UIView *)fetchAdView;

销毁广告

/**
 Call this method when you want to relase the ad, and the adView will be removed from your presenting view.

 @note After calling this method, if you need to continue using the MTGNativeAdvancedAd, you must reinitialize a MTGNativeAdvancedAd
*/
- (void)destroyNativeAd;

MTGNativeAdvancedAdDelegate 介绍

@protocol MTGNativeAdvancedAdDelegate <NSObject>

/**
 This method is called when ad is loaded successfully.
 */
- (void)nativeAdvancedAdLoadSuccess:(MTGNativeAdvancedAd *)nativeAd;

/**
 This method is called when ad failed to load.
 */
- (void)nativeAdvancedAdLoadFailed:(MTGNativeAdvancedAd *)nativeAd error:(NSError *)error;

/**
 Sent immediately before the impression of an MTGNativeAdvancedAd object will be logged.
 */
- (void)nativeAdvancedAdWillLogImpression:(MTGNativeAdvancedAd *)nativeAd;

/**
 This method is called when ad is clicked.
 */
- (void)nativeAdvancedAdDidClicked:(MTGNativeAdvancedAd *)nativeAd;

/**
 Called when the application is about to leave as a result of tapping.
 Your application will be moved to the background shortly after this method is called.
 */
- (void)nativeAdvancedAdWillLeaveApplication:(MTGNativeAdvancedAd *)nativeAd;

/**
 Will open the full screen view
 Called when opening storekit or opening the webpage in app

 */
- (void)nativeAdvancedAdWillOpenFullScreen:(MTGNativeAdvancedAd *)nativeAd;

/**
 Close the full screen view
 Called when closing storekit or closing the webpage in app
 */
- (void)nativeAdvancedAdCloseFullScreen:(MTGNativeAdvancedAd *)nativeAd;

/**
 This method is called when ad is Closed.
 */
- (void)nativeAdvancedAdClosed:(MTGNativeAdvancedAd *)nativeAd;

@end

示例代码

- (void)createNewNativeAd:(CGSize)size {

    _adManager = [[MTGNativeAdvancedAd alloc] initWithPlacementID:kNewNativePlacementId unitID:kNewNativeUnitID adSize:CGSizeMake(320, 90) rootViewController:self];
    _adManager.delegate = self;

    _adManager.showCloseButton = YES;
    _adManager.mute = NO;
    _adManager.autoPlay = YES;

    NSDictionary *styles = @{
        @"list": @[
                @{
                    // 目标元素
                    @"target": @"container",
                    // 样式值
                    @"values": @{

                            @"paddingTop": @(0),
                            @"paddingRight": @(0),
                            @"paddingBottom": @(0),
                            @"paddingLeft": @(0),

                            @"backgroundColor": @"#FC2E02",
                            @"fontSize": @(20),
                            @"color": @"#060602",
                            @"fontFamily": @"Apple Symbols"
                    }

                }
            ]
    };

    [_adManager setAdElementsStyle:styles];

}
- (void)loadButtonAction:(UIButton *)sender {
    [self log:@"start loading"];
    [self.adManager loadAd];

}
- (void)showButtonAction:(UIButton *)sender {

        if ([_adManager isAdReady]) {
            [self addAdView];
        }
}

激励视频接入

激励视频是Mintegral平台效果非常好的广告形式,用户可以通过观看一段广告视频而获取奖励,由于广告视频素材非常具有创意和吸引力,因此会引起很多用户的兴趣,进而点击广告产生转化收入。

广告效果示意:

导入头文件

集成激励视频广告,需要导入以下头文件:

#import <MTGSDK/MTGSDK.h>
#import <MTGSDKReward/MTGRewardAdManager.h>

静音处理

必须在load之前调用

/* Play the video mute or not in the beginning, defult is NO.  set true means mute*/
@property (nonatomic, assign) BOOL  playVideoMute;

计时设置

必须在load之前调用

/**
*  Set  alertView text,if you want to change the alertView text.
*
* @param title  alert title
* @param content    alertcontent
* @param confirmText    confirm button text
* @param cancelText     cancel button text

*/
- (void)setAlertWithTitle:(NSString *_Nullable)title
                        content:(NSString *_Nullable)content
                    confirmText:(NSString *_Nullable)confirmText
                     cancelText:(NSString *_Nullable)cancelText;

Reward Plus设置

必须在load之前调用
该API仅表示接受投放Reward plus的广告,下发奖励依然依赖SDK中 onVideoAdDismissed 回调的奖励数量货币信息参数(MTGRewardAdInfo)进行奖励发放。

/* This method is used to open RewardPlus for RewardVideo,if you need,please set this before loadVideo,defalue NO.
*/
@property (nonatomic,assign) BOOL openRewardPlus;
示例:
[MTGRewardAdManager sharedInstance].openRewardPlus = YES;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/**
* get the id of this request ad,call  after onAdLoadSuccess.
*/
- (NSString *_Nullable)getRequestIdWithUnitId:(nonnull NSString *)unitId;

请求广告

请求广告时,需传入对应的广告版位placementId和广告单元unitId。建议开发者在展示广告之前,提前进行广告请求,进而给素材等资源的下载提供时间,减少用户在展示广告时等待的时间,提高用户体验和广告时间。

/**
*  Called when load the video

*  @param placementId   - the placementId string of the Ad that display.
*  @param unitId      - the unitId string of the Ad that was loaded.
*  @param delegate    - reference to the object that implements MTGRewardAdLoadDelegate protocol; will receive load events for the given unitId.
*/
- (void) loadVideoWithPlacementId:(nullable NSString *)placementId
           unitId:(nonnull NSString *)unitId
         delegate:(nullable id <MTGRewardAdLoadDelegate>)delegate;

展示广告

展示广告之前建议先判断广告是否已经下载成功,如果视频可以播放SDK会返回成功信息,然后再传入对应的PlacementId、UntiId和viewController展示视频广告;如果返回失败,就放弃这次视频展示机会。
注意:RewardId激励信息里创建的奖励信息,如果对RewardId没有其他特殊要求,可以传"1";userId用于服务器端回调(userId只能是数字和字母),如果是客户端回调可以不传

/**
 *  Will return whether the given unitId is loaded and ready to be shown.
 *
 *  @param placementId - adPositionId value in Self Service
 *  @param unitId - adPositionId value in Self Service
 *
 *  @return - YES if the unitId is loaded and ready to be shown, otherwise NO.
 */
- (BOOL) isVideoReadyToPlayWithPlacementId:(nullable NSString *)placementId unitId:(nonnull NSString *)unitId;

/**
*  Called when show the video
*
*  @param placementId         - the placementId string of the Ad that display.
*  @param unitId         - the unitId string of the Ad that display.
*  @param rewardId       - the reward info you can set in mintegral portal
*  @param userId       - The user's unique identifier in your system
*  @param delegate       - reference to the object that implements MTGRewardAdShowDelegate protocol; will receive show events for the given unitId.
*  @param viewController - UIViewController that shouold be set as the root view controller for the ad
*/
- (void) showVideoWithPlacementId:(nullable NSString *)placementId
           unitId:(nonnull NSString *)unitId
     withRewardId:(nullable NSString *)rewardId
           userId:(nullable NSString *)userId
         delegate:(nullable id <MTGRewardAdShowDelegate>)delegate
   viewController:(nonnull UIViewController*)viewController;

Delegate介绍

MTGRewardAdLoadDelegate

/**
 *  This protocol defines a listener for ad video load events.
 */
@protocol MTGRewardAdLoadDelegate <NSObject>
@optional

/**
*  Called when the ad is loaded , but not ready to be displayed,need to wait load video
completely

*  @param placementId - the placementId string of the Ad that was loaded.
*  @param unitId - the unitId string of the Ad that was loaded.
*/
- (void)onAdLoadSuccess:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

/**
 *  Called when the ad is successfully load , and is ready to be displayed

 *  @param placementId - the placementId string of the Ad that was loaded.
 *  @param unitId - the unitId string of the Ad that was loaded.
 */
- (void)onVideoAdLoadSuccess:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

/**
 *  Called when there was an error loading the ad.

 *  @param placementId - the placementId string of the Ad that was loaded.
 *  @param unitId      - the unitId string of the Ad that failed to load.
 *  @param error       - error object that describes the exact error encountered when loading the ad.
 */
- (void)onVideoAdLoadFailed:(nullable NSString *)placementId unitId:(nullable NSString *)unitId error:(nonnull NSError *)error;

@end

MTGRewardAdShowDelegate

/**
 *  This protocol defines a listener for ad video show events.
 */
@protocol MTGRewardAdShowDelegate <NSObject>
@optional

/**
 *  Called when the ad display success

 *  @param placementId - the placementId string of the Ad that display success.
 *  @param unitId - the unitId string of the Ad that display success.
 */
- (void)onVideoAdShowSuccess:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

/**
 *  Called when the ad failed to display for some reason

 *  @param placementId      - the placementId string of the Ad that failed to be displayed.
 *  @param unitId      - the unitId string of the Ad that failed to be displayed.
 *  @param error       - error object that describes the exact error encountered when showing the ad.
 */
- (void)onVideoAdShowFailed:(nullable NSString *)placementId unitId:(nullable NSString *)unitId withError:(nonnull NSError *)error;

/**
 *  Called only when the ad has a video content, and called when the video play completed.

 *  @param placementId - the placementId string of the Ad that video play completed.
 *  @param unitId - the unitId string of the Ad that video play completed.
 */
- (void) onVideoPlayCompleted:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

/**
 *  Called only when the ad has a endcard content, and called when the endcard show.

 *  @param placementId - the placementId string of the Ad that endcard show.
 *  @param unitId - the unitId string of the Ad that endcard show.
 */
- (void) onVideoEndCardShowSuccess:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

/**
 *  Called when the ad is clicked
 *
 *  @param placementId - the placementId string of the Ad clicked.
 *  @param unitId - the unitId string of the Ad clicked.
 */
- (void)onVideoAdClicked:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

/**
 *  Called when the ad has been dismissed from being displayed, and control will return to your app
 *
 *  @param placementId      - the placementId string of the Ad that has been dismissed
 *  @param unitId      - the unitId string of the Ad that has been dismissed
 *  @param converted   - BOOL describing whether the ad has converted
 *  @param rewardInfo  - the rewardInfo object containing the info that should be given to your user.
 *   rewardInfo.rewardName 为货币名称。(long)rewardInfo.rewardAmount 为货币数量。
 */
- (void)onVideoAdDismissed:(nullable NSString *)placementId unitId:(nullable NSString *)unitId withConverted:(BOOL)converted withRewardInfo:(nullable MTGRewardAdInfo *)rewardInfo;

/**
 *  Called when the ad  did closed;
 *
 *  @param unitId - the unitId string of the Ad that video play did closed.
 *  @param placementId - the placementId string of the Ad that video play did closed.
 */
- (void)onVideoAdDidClosed:(nullable NSString *)placementId unitId:(nullable NSString *)unitId;

@end

示例代码

#import "MTGRewardVideoViewController.h"
#import <MTGSDKReward/MTGRewardAdManager.h>
#import <MTGSDK/MTGSDK.h>

@interface MTGRewardVideoViewController ()
<MTGRewardAdLoadDelegate,MTGRewardAdShowDelegate>

- (void)viewDidLoad {
   [[MTGRewardAdManager sharedInstance] loadVideoWithPlacementId:KRewardPlacementID unitId:KRewardUnitID delegate:self];    
}

- (IBAction)showVideoButtonAction:(id)sender
{
   //Check whether video has been downloaded successfully before displaying ad
if ([[MTGRewardAdManager sharedInstance] isVideoReadyToPlayWithPlacementId:@"your placementId" unitId:@"your unitId"]) {

     [[MTGRewardAdManager sharedInstance] showVideoWithPlacementId:@"your placementId"  unitId:@"your unitId"] withRewardId:@"your rewardid"] userId:@"" delegate:self viewController:self];

    } 
}

设置服务端回调(可选)

您可以根据需要选择通过SDK或者服务端回调信息。若需要设置服务端回调,可以在后台添加callbackURL,Mintegral会在视频播放完成后调用callbackurl给予信息的回调。

1.创建广告位时设置回调方式

当Mintegral服务端获知用户完成任务后,通过Callback URL通知开发者服务端,为用户增加积分,对开发者来说,该方式实现起来稍微复杂,但安全性高。

2 声明callbackUrl,只需要修改域名部分

3 Mintegral Server获知获知到该user_id增加积分后,通过callback url通知开发者服务端。callback url附加的参数如下:

参数 说明
user_id 用户ID,由开发者设置
trans_id 传输ID,Mintegral服务端生成,具有唯一性
reward_amount 用户应该获得的积分
reward_name 积分的名称
sign 加密标识 MD5(user_id_reward_amount_trans_id_security_key)
unit_id 广告位ID

4 开发者服务端一旦收到postback后,需给MTG服务端返回200或403

200 means:User has been rewarded successfully.

403 means:abnormal 

1.sign does not match

2.user_id does not exist

5 Mintegral Server发起Postback后,若超时(20秒)无响应,则在24小时内每隔5分钟重试一次。

插屏图片广告接入

插屏广告会在屏幕上展示一条大图广告,用户可以通过关闭按钮来关闭广告。

注:MIntegral推出了全新的InterstitalVideo广告类型,相比普通Interstital广告会有更好的视觉效果和体验。该广告类型仅对部分开发者提供,如有需要请联系您的AM 或 致信developer@mintegral.com

广告效果示意:
![Interstitial](./

导入头文件

#import <MTGSDK/MTGSDK.h>
#import <MTGSDKInterstitial/MTGInterstitialAdManager.h>

MTGInterstitialAdManager初始化

初始化时,需要传入对应的广告位的PlacementId和UnitID,可以通过adCategory参数控制广告类型,如果对广告类型没有特殊要求,填MTGOFFERWALL_AD_CATEGORY_ALL(或者数字0)即可。

/**
*   Initialize the interstitial ads manager.
*  @param placementId     The id of the ad placement. You can create your placement id from our Portal.
*  @param unitId         The id of the ad unit. You can create your unit id from our Portal.
*  @param adCategory     Decide what kind of ads you want to retrieve. Games, apps or all of them. The default is All.
*/
- (nonnull instancetype)initWithPlacementId:(nullable NSString *)placementId
                                     unitId:(nonnull NSString *)unitId
                                 adCategory:(MTGInterstitialAdCategory)adCategory;

加载广告和展示广告

/**
 *  Called when load the Interstitial
 *
 *  @param delegate reference to the object that implements MTGInterstitialAdLoadDelegate protocol; will receive load events for the given unitId.
 */
- (void)loadWithDelegate:(nullable id <MTGInterstitialAdLoadDelegate>) delegate;

/**
 *  Called when show the Interstitial
 *
 *  @param delegate       reference to the object that implements MTGInterstitialAdShowDelegate protocol; will receive show events for the given unitId.

 *  @param viewController The UIViewController that will be used to present Interstitial Controller. If not set, it will be the root viewController of your current UIWindow. But it may failed to present our Interstitial controller if your rootViewController is presenting other view controller. So set this property is necessary.

 */
- (void)showWithDelegate:(nullable id <MTGInterstitialAdShowDelegate>)delegate presentingViewController:(nullable UIViewController *)viewController;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/**
* get the id of this request ad,call  after onInterstitialLoadSuccess.
*/
@property (nonatomic,copy,readonly)   NSString * _Nullable requestId;

示例代码

#import "MTGInsterstialViewController.h"
#import <MTGSDKInterstitial/MTGInterstitialAdManager.h>

@interface MTGInsterstialViewController ()<MTGInterstitialAdLoadDelegate,MTGInterstitialAdShowDelegate>

@property (nonatomic, strong) MTGInterstitialAdManager *interstitialAdManager;

@end

@implementation MTGInsterstialViewController

- (void)viewDidLoad {

}

- (IBAction)initAdManagerButtonAction:(id)sender
{

    if (!_interstitialAdManager) {
        _interstitialAdManager = [[MTGInterstitialAdManager alloc]initWithPlacementId:KInterstitialPlacementID unitId:KInterstitialUnitID adCategory:0];
        [self log:@"MTGInterstitialAdManager init"];

    }
}

- (IBAction)loadInsterstialButtonAction:(id)sender
{
    if (!_interstitialAdManager) {
       _interstitialAdManager = [[MTGInterstitialAdManager alloc]initWithPlacementId:KInterstitialPlacementID unitId:KInterstitialUnitID adCategory:0];
    }
        [_interstitialAdManager loadWithDelegate:self];
}

- (IBAction)showInsterstialButtonAction:(id)sender
{
    if (!_interstitialAdManager) {
        _interstitialAdManager = [[MTGInterstitialAdManager alloc]initWithPlacementId:KInterstitialPlacementID unitId:KInterstitialUnitID adCategory:0];
    }

    [_interstitialAdManager showWithDelegate:self presentingViewController:self];
}

#pragma mark - Interstitial Delegate Methods
- (void) onInterstitialLoadSuccess{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialLoadSuccess:adManager{

    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterstitialLoadFail:(nonnull NSError *)error{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialLoadFail:(nonnull NSError *)error adManager:(MTGInterstitialAdManager * _Nonnull)adManager{

    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterstitialShowSuccess{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialShowSuccess:adManager{

    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterstitialShowFail:(nonnull NSError *)error{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialShowFail:(nonnull NSError *)error adManager:(MTGInterstitialAdManager * _Nonnull)adManager{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialClosed{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialClosed:adManager{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialAdClick{

    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterstitialAdClick:adManager{

    [self log:NSStringFromSelector(_cmd)];
}

@end

插屏视频广告接入

插屏视频广告是插屏广告的升级版本,展示广告时会给用户展示一个全屏或半屏的视频,通过更有吸引力的视频提高用户的兴趣。
广告效果示意:

1 导入头文件

#import <MTGSDK/MTGSDK.h>
#import <MTGSDKInterstitialVideo/MTGInterstitialVideoAdManager.h>

2 MTGInterstitialVideoAdManager的初始化

请求视频广告,需传入对应的广告位的PlacementID 和 UnitID。

/**
*   Initialize the InterstitialVideo ads manager.
*  @param placementId     The id of the ad placement. You can create your placement id from our Portal.
*  @param unitId         The id of the ad unit. You can create your unit id from our Portal.
*  @param delegate       - reference to the object that implements. 
*/

- (nonnull instancetype)initWithPlacementId:(nullable NSString *)placementId
                                     unitId:(nonnull NSString *)unitId
                                   delegate:(nullable id<MTGInterstitialVideoDelegate>)delegate;

3 请求广告和展示广告

/**
 * Begins loading ad content for the interstitialVideo.
 *
 * You can implement the `onInterstitialVideoLoadSuccess:` and `onInterstitialVideoLoadFail: adManager:` methods of
 * `MTGInterstitialVideoDelegate` if you would like to be notified as loading succeeds or
 * fails.
 */
- (void)loadAd;

/** @name Presenting an interstitialVideo Ad */

/**
 * Presents the interstitialVideo ad modally from the specified view controller.
 *
 * @param viewController The view controller that should be used to present the interstitialVideo ad.
 */
- (void)showFromViewController:(UIViewController *_Nonnull)viewController;*_Nonnull)viewController;

/**
*  Whether the given unitId is loaded and ready to be shown.

* @param placementId   - the placementId string of the Ad that display.
*  @param unitId - adPositionId value in Self Service.
*
*  @return - YES if the unitId is loaded and ready to be shown, otherwise NO.
*/
- (BOOL)isVideoReadyToPlayWithPlacementId:(nullable NSString *)placementId unitId:(nonnull NSString *)unitId;

静音处理

必须在load之前调用

/* Play the video mute or not in the beginning, defult is NO.  set true means mute*/
@property (nonatomic, assign) BOOL  playVideoMute;

插屏视频奖励模式接口

必须在load之前调用

/**
*  Whether to make InterstitialVideo reward settings
*
* @param ivRewardMode MTGIVRewardMode
* @param playRate Set when to show the reward alert,range of 0~1,
    eg: set playTime 0.6,indicates 60%

 NOTE:Must be called before loadAd
*/
- (void)setIVRewardMode:(MTGIVRewardMode)ivRewardMode playRate:(CGFloat)playRate;
/**
*   Make InterstitialVideo reward settings,
*
* @param ivRewardMode MTGIVRewardMode
* @param playTime Set when to show the reward alert,range of 0~100
 NOTE:Must be called before loadAd
*/
- (void)setIVRewardMode:(MTGIVRewardMode)ivRewardMode playTime:(NSInteger)playTime;

/**
*  Set alertView text,if you want to change the alertView text.
*
* @param title  alert title
* @param content    alertcontent
* @param confirmText    confirm button text
* @param cancelText     cancel button text

 NOTE:Must be called before loadAd
*/
- (void)setAlertWithTitle:(NSString *_Nullable)title
                        content:(NSString *_Nullable)content
                    confirmText:(NSString *_Nullable)confirmText
                     cancelText:(NSString *_Nullable)cancelText;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/**
* get the id of this request ad,call  after onInterstitialAdLoadSuccess.
*/
- (NSString *_Nullable)getRequestIdWithUnitId:(nonnull NSString *)unitId;

示例代码

#import "MTGInsterstialVideoViewController.h"
#import <MTGSDKInterstitialVideo/MTGInterstitialVideoAdManager.h>

@interface MTGInsterstialVideoViewController ()<MTGInterstitialVideoDelegate>

//Demo InsterstialVideo View
@property (nonatomic, strong) UITextView *textView;

//Log Label
@property (nonatomic, strong) UILabel *logLabel;

@property (nonatomic,strong)  MTGInterstitialVideoAdManager *ivAdManager;

@end

@implementation MTGInsterstialVideoViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (IBAction)initAdManagerButtonAction:(id)sender
{
    if (!_ivAdManager) {
       _ivAdManager = [[MTGInterstitialVideoAdManager alloc]initWithPlacementId:KInterstitialVideoPlacementId unitId:KInterstitialVideoUnitID delegate:self];
        _ivAdManager.delegate = self;

    }
}

- (IBAction)loadInsterstialButtonAction:(id)sender
{
    if (!_ivAdManager) {
       _ivAdManager = [[MTGInterstitialVideoAdManager alloc]initWithPlacementId:KInterstitialVideoPlacementId unitId:KInterstitialVideoUnitID delegate:self];
        _ivAdManager.delegate = self;

//        [_ivAdManager setAlertWithTitle:@"关闭?" content:@"确认关闭?" confirmText:@"关闭" cancelText:@"继续计时"];
//        [_ivAdManager setIVRewardMode:MTGIVRewardPlayMode playTime:1];
//        [_ivAdManager setIVRewardMode:MTGIVRewardCloseMode playRate:0.8];

    }
        [_ivAdManager loadAd];
}

- (IBAction)showInsterstialButtonAction:(id)sender
{
    if (!_ivAdManager) {
       _ivAdManager = [[MTGInterstitialVideoAdManager alloc]initWithPlacementId:KInterstitialVideoPlacementId unitId:KInterstitialVideoUnitID delegate:self];
       _ivAdManager.delegate = self;

    }

    if ([_ivAdManager isVideoReadyToPlayWithPlacementId: KInterstitialVideoPlacementId unitId:KInterstitialVideoUnitID]) {
         [_ivAdManager showFromViewController:self];
    }
}

#pragma mark - Utility

#pragma mark - Interstitial Delegate Methods

- (void) onInterstitialAdLoadSuccess:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterstitialVideoLoadSuccess:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];

}
- (void) onInterstitialVideoLoadFail:(nonnull NSError *)error adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager;{
    [self log:NSStringFromSelector(_cmd)];

}

- (void) onInterstitialVideoShowSuccess:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];

}

- (void) onInterstitialVideoShowFail:(nonnull NSError *)error adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];

}

- (void) onInterstitialVideoAdClick:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];

}

- (void)onInterstitialVideoAdDismissedWithConverted:(BOOL)converted adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];

}
- (void) onInterstitialVideoPlayCompleted:(MTGInterstitialVideoAdManager *_Nonnull)adManager {
    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterstitialVideoEndCardShowSuccess:(MTGInterstitialVideoAdManager *_Nonnull)adManager {
    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterstitialVideoAdDidClosed:(MTGInterstitialVideoAdManager *_Nonnull)adManager{

    [self log:NSStringFromSelector(_cmd)];
}

     /**
    *  If iv reward is set, you will receive this callback
    *  @param achieved  Whether the video played to required rate
    * @param alertWindowStatus MTGIVAlertWindowStatus
    */

- (void)onInterstitialVideoAdPlayVideo:(BOOL)achieved alertWindowStatus:(MTGIVAlertWindowStatus)alertWindowStatus adManager:(MTGInterstitialVideoAdManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];
}

@end

交互式广告接入

交互式广告是Mintegral推出的全新广告形态,通过该形式用户可以实际参与一个精心设计的交互广告(比如试玩一个游戏Demo),进而大大提升转化效果。当前广告内容以Playable为主。

注:该广告类型仅对部分开发者提供,如有需要请联系您的AM 或 致信developer@mintegral.com

广告效果示意:

导入头文件

#import <MTGSDK/MTGSDK.h>
#import <MTGSDKInterActive/MTGInterActiveManager.h>

初始化MTGInterActiveManager

初始化MTGInterActiveManager,并且传入Placementid,UnitId,然后设置MTGInterActiveManager的delegate。

- (nonnull instancetype)initWithPlacementId:(nullable NSString *)placementId
                                     unitId:(nonnull NSString *)unitId
                         withViewController:(nonnull UIViewController *)viewController;

计时设置

注意:必须放在load方法前面才生效

/**
*  Set  alertView text,if you want to change the alertView text.
*
* @param title  alert title
* @param content    alertcontent
* @param confirmText    confirm button text
* @param cancelText     cancel button text

*/
- (void)setAlertWithTitle:(NSString *_Nullable)title
                        content:(NSString *_Nullable)content
                    confirmText:(NSString *_Nullable)confirmText
                     cancelText:(NSString *_Nullable)cancelText;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/**
* get the id of this request ad,call  after onInterActiveLoadSuccess.
*/
@property (nonatomic, readonly)   NSString * _Nullable requestId;

请求广告和展示广告

- (void)loadAd;
- (void)showFromViewController:(UIViewController *_Nonnull)viewController;

示例代码

#import "MTGInterActiveViewController.h"

#import <MTGSDKInterActive/MTGInterActiveManager.h>

@interface MTGInterActiveViewController ()<MTGInterActiveDelegate>

@property (nonatomic, strong) MTGInterActiveManager *instersActiveAdManager;

@end

@implementation MTGInterActiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];

}

- (IBAction)initAdManagerButtonAction:(id)sender
{
    if (!_instersActiveAdManager) {
        _instersActiveAdManager = [[MTGInterActiveManager alloc]initWithPlacementId:KInterActivePlacementId unitId:KInterActiveUnitID withViewController:self];
        _instersActiveAdManager.delegate = self;
        [self log:@"MTGInterActiveManager init"];

    }
}

- (IBAction)loadInstersActiveButtonAction:(id)sender
{
    if (!_instersActiveAdManager) {
       _instersActiveAdManager = [[MTGInterActiveManager alloc]initWithPlacementId:KInterActivePlacementId unitId:KInterActiveUnitID withViewController:self];
        _instersActiveAdManager.delegate = self;
    }
    [_instersActiveAdManager loadAd];
}

- (IBAction)showInstersActiveButtonAction:(id)sender
{
    if (!_instersActiveAdManager) {
       _instersActiveAdManager = [[MTGInterActiveManager alloc]initWithPlacementId:KInterActivePlacementId unitId:KInterActiveUnitID withViewController:self];
        _instersActiveAdManager.delegate = self;
    }

    [_instersActiveAdManager showAd];
}

#pragma mark - instersActive Delegate Methods

- (void) onInterActiveLoadSuccess:(MTGInterActiveResourceType)resourceType adManager:(MTGInterActiveManager *_Nonnull)adManager{

    [self log:[NSString stringWithFormat:@"rType:%d %@",(int)resourceType,NSStringFromSelector(_cmd)]];
}

- (void) onInterActiveLoadFailed:(nonnull NSError *)error adManager:(MTGInterActiveManager *_Nonnull)adManager{
    [self log:error.description];
}

- (void) onInterActiveShowSuccess:(MTGInterActiveManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterActiveShowFailed:(nonnull NSError *)error adManager:(MTGInterActiveManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterActiveAdClick:(MTGInterActiveManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];
}

- (void) onInterActiveAdDismissed:(MTGInterActiveManager *_Nonnull)adManager{
    [self log:NSStringFromSelector(_cmd)];
}
- (void) onInterActiveAdManager:(MTGInterActiveManager *)adManager playingComplete:(BOOL)completeOrNot {
    NSString *des = [NSString stringWithFormat:@"finished playing or not : %@", @(completeOrNot)];
    [self log:des];
}

@end

开屏广告接入

开屏式广告是目前比较流行的广告形式之一。这种类型比较适合投放电商、品牌类广告,流量接入上也很适合接入应用类流量。用户可以点击广告跳转到广告落地页,或者点击右上角的“跳过”按钮,跳转到app内容首页。开屏广告会在您的应用开启时加载,展示完毕后自动关闭并进入您的应用主界面。

分类:开屏广告分为半屏和全屏,在半屏情况下,支持定义logo图片,同时也支持横竖屏。

广告效果示意:

导入头文件

#import <MTGSDK/MTGSDK.h>
#import <MTGSDKSplash/MTGSplashAD.h>

初始化MTGSplashAD

初始化MTGSplashAD时,可以进行倒计时设置(传0时,为5s)、是否允许跳过设置(不设置时,默认为允许跳过)、半屏全屏设置(设置半屏时可自定义logo的视图大小)、横竖屏设置(传0时,取开发者当前的设备方向)

/**
 Initialize a MTGSplashAD instance.
 @param placementId placementId String.
 @param unitID unitID String.
 @param countdown time duration of the ad can be showed. Should be range of 2-10s.
 @param allowSkip Whether or not to allow user to skip ad when showing.

 */
- (instancetype)initWithPlacementID:(nullable NSString *)placementID
                             unitID:(NSString *)unitID
                          countdown:(NSUInteger)countdown
                          allowSkip:(BOOL)allowSkip;

/**
 Initialize a MTGSplashAD instance with more detailed info.

 @param placementId placementId String.
 @param unitID unitID String.
 @param countdown time duration of the ad can be showed. Should be range of 2-10s.
 @param allowSkip whether or not to allow user to skip ad when showing.
 @param customViewSize if you want to display your own custom view on the ad area, you should pass the corresponding CGSize of your custome view.
 @param preferredOrientation specify preferred orientation to show the ad.

 @note  1. when you showing ad on the portrait mode, the height of the customViewSize should not           greater than 25% of the device's height.
        2. when you showing ad on the landscape mode, the width of the customViewSize should not greater than 25% of the device's width.
 */
- (instancetype)initWithPlacementID:(nullable NSString *)placementID
                             unitID:(NSString *)unitID
                          countdown:(NSUInteger)countdown
                          allowSkip:(BOOL)allowSkip
                     customViewSize:(CGSize)customViewSize
               preferredOrientation:(MTGInterfaceOrientation)preferredOrientation;

注:customViewSize 的大小不能超过屏幕的 0.25

设置代理

/* Set delegate to receive protocol event.  */
@property (nonatomic, weak) id <MTGSplashADDelegate> delegate;

背景图和背景颜色设置

/* Set this to show your own background image when loading ad. */
@property (nonatomic, strong) UIImage *backgroundImage;

/* Set this to show your own background color when loading ad. */
@property (nonatomic, copy) UIColor *backgroundColor;

获取Request ID

若广告展示过程中发现问题,可以通过该方法将 Request ID 记录并反馈到MTG.需要在 load success 之后调用

/* get the id of this request ad,call after splashADPreloadSuccess || splashADLoadSuccess*/
@property (nonatomic, readonly, copy) NSString *requestID;

我们提供两种请求展示广告方式:

1、(推荐)预先请求广告,再在合适的时机去展示广告

我们建议您在合适的时机调用preload,生命周期内preload时机最好不要距离show时间过长,建议不超过30分钟。调用preload后,在show场景时可以通过isADReadyToShow判断,如果为Yes则调用show。如果为No则调用loadAndShowInKeyWindow。
2、实时请求并展示广告

预先请求广告,再在合适的时机去展示广告

注:

  1. 展示广告前可以调用isADReadyToShow方法,来检测本地是否有缓存广告。
  2. customView可传入自定义logo的视图,(customView的视图大小应该与初始化时设置的customViewSize大小一致,不一致时以customViewSize这个为logo试图预留的大小为准)
/**
 Preload a ad and then use `[MTGSplashAD showInKeyWindow:customView:]` to show the ad.
 @note  You should always call this method on the main thread.
 */
- (void)preload;

/**
 Whether or not if there was a available ad to show.

 @return YES means there was a available ad, otherwise NO.
 */
- (BOOL)isADReadyToShow;

/**
 if there was a available ad to show, you can call this method to show the ad.

 @param window must be the key window of the application.
 @param customView display your own custom view, e.g. logo view.

 @note  You should always call this method on the main thread.
 */
- (void)showInKeyWindow:(UIWindow *)window customView:(nullable UIView *)customView;

实时请求并展示广告

timeout:SDK在指定时间内没有完成广告加载(即加载超时),则直接关闭。单位是ms。传0时,值为5000ms。

/**
 Show the ad after load successfully.

 @param window must be the key window of the application.
 @param customView display your own custom view, e.g. logo view.
 @param timeout load timeout, unit should be millisecond. If you passed 0 then 5000ms would be used.

 @note  You should always call this method on the main thread.
 */
- (void)loadAndShowInKeyWindow:(UIWindow *)window
                   customView:(nullable UIView *)customView
                    timeout:(NSInteger)timeout;

每次preload都会刷新缓存。preload之后可以调用showInKeyWindow:customView,也可以调用showloadAndShowInKeyWindow:customView:timeout:,这两种都会优先使用preload之后的缓存。

MTGSplashAD回调

/* Called when preloading ad successfully. */
- (void)splashADPreloadSuccess:(MTGSplashAD *)splashAD;
/* Called when preloading ad failed. */
- (void)splashADPreloadFail:(MTGSplashAD *)splashAD error:(NSError *)error;
/* Called when loading ad successfully. */
- (void)splashADLoadSuccess:(MTGSplashAD *)splashAD;
/* Called when loading ad failed. */
- (void)splashADLoadFail:(MTGSplashAD *)splashAD error:(NSError *)error;
/* Called when showing ad successfully. */
- (void)splashADShowSuccess:(MTGSplashAD *)splashAD;
/* Called when showing ad failed. */
- (void)splashADShowFail:(MTGSplashAD *)splashAD error:(NSError *)error;
/* Called when the application is about to leave as a result of tap event.
   Your application will be moved to the background shortly after this method is called. */
- (void)splashADDidLeaveApplication:(MTGSplashAD *)splashAD;
/* Called when click event occured. */
- (void)splashADDidClick:(MTGSplashAD *)splashAD;
/* Called when ad is about to close. */
- (void)splashADWillClose:(MTGSplashAD *)splashAD;
/* Called when ad did close. */
- (void)splashADDidClose:(MTGSplashAD *)splashAD;
/* Called when remaining countdown update. */
- (void)splashAD:(MTGSplashAD *)splashAD timeLeft:(NSUInteger)time;

示例代码

#import "MTGSplashAdViewController.h"
#import <MTGSDKSplash/MTGSplashAD.h>
#import <MTGSDK/MTGSDK.h>

@interface MTGSplashAdViewController () <MTGSplashADDelegate>

@property (nonatomic, strong) MTGSplashAD *splashAD;
@property (nonatomic, strong) UISwitch *useLogo;
@property (nonatomic, strong) UISwitch *skip;

- (void)createSplashAD {

    if (self.useLogo.on) {
        self.splashAD = [[MTGSplashAD alloc]initWithPlacementID:kSplashPlacementID unitID:kSplashUnitID countdown:10 allowSkip:self.skip.on customViewSize:CGSizeMake(200, 95) preferredOrientation:0];
    } else {
        self.splashAD = [[MTGSplashAD alloc]initWithPlacementID: kSplashPlacementID unitID:kSplashUnitID countdown:10 allowSkip:self.skip.on customViewSize:CGSizeZero preferredOrientation:0];

    }    
}

//Load Video
- (IBAction)preloadButtonAction:(id)sender{
    [self createSplashAD];

    [self log:@"splash ad is loading"];
    [self.splashAD preload];

}
//isReady
- (void)isReadyButtonAction:(UIButton *)button {
    [self createSplashAD];

    BOOL ready = [self.splashAD isADReadyToShow];
    [self log:[NSString stringWithFormat:@"isReady : %@", ready ? @"true" : @"false"]];

}

//Show Video
- (IBAction)showButtonAction:(id)sender
{
    [self createSplashAD];

    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    UIView *logoView = nil;

    if (self.useLogo.on) {
        logoView = [self logoView];
    }

    [self.splashAD showInKeyWindow:keyWindow customView:logoView];

}
//LoadNShow
- (void)LoadNShowButtonAction:(UIButton *)btn {

    [self createSplashAD];

    UIView *logoView = nil;
    if (self.useLogo.on) {
        logoView = [self logoView];
    }

    [self log:@"splash ad is loading"];
    UIWindow *keyWindow = [UIApplication sharedApplication].keyWindow;
    [self.splashAD loadAndShowInKeyWindow:keyWindow customView:logoView timeout:5000];

}
//logoView
- (UIView *)logoView {

    UIImageView *logo = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"logo"]];
    logo.frame = CGRectMake(0, 0, 100, 100);
    return logo;
}

#pragma mark - MTGSplashADDelegate

- (void)splashADPreloadSuccess:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, preload success", splashAD.unitID]];
}
- (void)splashADPreloadFail:(MTGSplashAD *)splashAD error:(NSError *)error {
    [self log:[NSString stringWithFormat:@"unitId = %@, preload error : %@", splashAD.unitID, error]];
}

// 开屏广告素材加载成功
- (void)splashADLoadSuccess:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, load success", splashAD.unitID]];
  }
// 开屏广告素材加载失败
- (void)splashADLoadFail:(MTGSplashAD *)splashAD error:(NSError *)error {
    [self log:[NSString stringWithFormat:@"unitId = %@, load error : %@", splashAD.unitID, error]];
}
// 展示成功
- (void)splashADShowSuccess:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, show success", splashAD.unitID]];
}
// 展示失败
- (void)splashADShowFail:(MTGSplashAD *)splashAD error:(NSError *)error {
    [self log:[NSString stringWithFormat:@"unitId = %@, show error : %@", splashAD.unitID, error]];

}
// 离开应用
- (void)splashADDidLeaveApplication:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, leave app", splashAD.unitID]];
}

// 点击
- (void)splashADDidClick:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, did click", splashAD.unitID]];
}

// 将要关闭
- (void)splashADWillClose:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, ad will close", splashAD.unitID]];

}
// 已经关闭
- (void)splashADDidClose:(MTGSplashAD *)splashAD {
    [self log:[NSString stringWithFormat:@"unitId = %@, ad closed", splashAD.unitID]];
}

// 倒计时
- (void)splashAD:(MTGSplashAD *)splashAD timeLeft:(NSUInteger)time {
    [self log:[NSString stringWithFormat:@"unitId = %@, ad countdown : %@", splashAD.unitID, @(time)]];
}

@end

Test ID

您在测试期间所获取的广告均为Mintegral的正式广告,因此会受到算法智能优化的影响,如果测试期间经常load失败返回EXCEPTION_RETURN_EMPTY,可使用以下测试id进行测试。

AppKey 7c22942b749fe6a6e361b675e96b3ee9
AppID 118692
Ad format Sample ad unit ID Placement ID
Banner 146898 138804
Native 146891 138797
Auto Rending Native 262716 204222
Rewarded Video 146892 138798
Static Interstitial 146896 138802
Interstitial Video 146894 138800
Interactive Ads 146897 138803
Splash 215246 177221

常见问题

1、为什么要做preload?
答:preload预加载数据,提升load加载数据的效率,提升用户体验。

2、为什么广告第一次跳转很慢?
答:由于跳转过程中要跳好多次,所以第一次会比较慢,第二次有了点击缓存,会快很多。开发者可以在这个时间段设置Loading对话框。

3、为什么有时候拉取不到广告?
答:请查看AppId、AppKey、UnitId等信息是否填写正确,之后查看后台单子没有投放、投放状态是否正确。

4、为什么offer中出现了两种语言?
答:由于根据ip等信息判断区域,所以会返回对应区域的语言。又由于英文是通用语言,所以offer中会出现英文和对应区域的语言。

5、为什么有时候app下载不下来?
答:由于AppStore网络问题或者apple账号可能不是vpn去的国家,导致app不能下载。

6、广告源下发数量有多少?
答:某个地区的广告源数量为各个广告主想要投放此地区广告的数量总和,当请求的广告数超出此数量时,下发的广告数量以此地区广告数量总数为准。

7、Native广告图片缓存时间
答:Native广告图片的缓存时间为7天

接口状态返回说明

状态码 msg 含义
-1 EXCEPTION_RETURN_EMPTY 没有广告填充,可能导致的原因:1.您在测试期间所获取的广告均为Mintegral的正式广告,因此会受到算法智能优化的影响,若一段时间内大量加载和展示广告,可能导致一段时间后没有广告填充的现象。
-10 EXCEPTION_SIGN_ERROR appID和appKey不匹配,解决方案:检查APPkey和APPID是否填写正确,APPkey可以在应用设置(APP Setting)模块顶部获取
-9 EXCEPTION_TIMEOUT 请求超时
-1201 EXCEPTION_UNIT_NOT_FOUND 该unitID不存在/填写错误
-1202 EXCEPTION_UNIT_ID_EMPTY unitID没传
-1203 EXCEPTION_UNIT_NOT_FOUND_IN_APP 在该appID和unitID不匹配
-1205 EXCEPTION_UNIT_ADTYPE_ERROR 传入的unitID广告类型不符
-1208 EXCEPTION_UNIT_BIDDING_TYPE_ERROR UnitID竞价模式和请求API不匹配,UnitID竞价模式一旦创建不可更改,需要重新创建新的UnitID
-1301 EXCEPTION_APP_ID_EMPTY appID没有传入
-1302 EXCEPTION_APP_NOT_FOUND 该appID不存在/填写错误
-1904 EXCEPTION_IV_RECALLNET_INVALIDATE 请求时的网络状态不对,一般是SDK初始化还未完成就去请求导致的
-1915 EXCEPTION_FILTER_BY
_PLACEMENTID_INCONSISTENT
PlacementId 填写错误
-2102 EXCEPTION_SERVICE_REQUEST
_OS_VERSION_REQUIRED
无法取得osVersion,一般是GDPR开关导致的
-129300060 kMTGErrorCodeUnknownError 未知错误
-129300061 kMTGErrorCodeRewardVideoFailedTo
LoadVideoData
无效广告
-129300068 kMTGErrorCodeRewardVideoFailedTo
LoadMd5Invalid
MD5校验失败
-129300001 KMTGErrorCodeEmptyUnitId unit id 为空
-129300002 KMTGErrorCodeEmptyBidToken BidToken 为空
-12930001 kMTGErrorCodeNoAds 没有广告返回
-12930003 kMTGErrorCodeURLisEmpty 返回的URL为空
-12930004 kMTGErrorCodeNoAdsAvailableToPlay 没有可播放的广告
-12930006 kMTGErrorCodeFailedToLoad 请求广告失败
-12930007 kMTGErrorCodeFailedToShow 展示失败
-12930009 kMTGErrorCodeDailyLimit 展示量达到限制
-12930010 kMTGErrorCodeLoadAdsTimeOut 请求超时
-12930011 kMTGErrorCodeMaterialLoadFailed 资源加载失败
-12940001 kMTGErrorCodeNoSupportPopupWindow 不支持GDPR弹窗

欧盟GDPR版本须知:

从2018.5.2开始,欧盟的“通用数据保护条例”(GDPR)将生效。 开发者需要更新Mintergal SDK并按以下方法集成,否则会影响广告正常投放。同时,我们更新了Mintegral隐私政策

接口介绍

1、弹出关于隐私政策的弹窗,此方法需在SDK初始化之前调用。

- (void)showConsentInfoTips:(nullable void (^)(BOOL consentStatus, NSError *_Nullable error))callback;

示例代码:

  [[MTGSDK sharedInstance] showConsentInfoTips:^(BOOL consentStatus, NSError * _Nullable error) {
        if (error == nil) {
            BOOL status = consentStatus;
            NSString * info = [NSString stringWithFormat: @"consentStatus = %d", status];
            [self log:info];
            _authorizationUserPrivate = YES;
        }else{
            [self log:error.localizedDescription];
        }
    }];

2、设置是否获取用户信息的开关,此方法也需要在SDK初始化之前调用

- (void)setConsentStatus:(BOOL)agree;

示例代码:

  [[MTGSDK sharedInstance] setConsentStatus:YES];//表示用户同意收取信息

注意事项

1.如果不收集用户信息,将会影响广告投放,可能会引起没有广告返回的情况,请知悉。
2.对于欧盟用户,开发者集成时,建议在征得用户同意之前,先不要初始化SDK,以免引起不必要的麻烦。

CCPA准备

2018年6月28日,美国加利福尼亚州(“加州”)颁布了《2018年加州消费者隐私法案》("CCPA"),旨在加强消费者隐私权和数据安全保护,将于2020年1月1日生效。对于加州用户,您可以基于用户的选择通过setDoNotTrackStatus接口进行设置。设置完成后,Mintegral将不再基于用户设备信息向该用户展示个性化推荐广告,也不会将该用户设备信息同步至其他第三方合作伙伴。该API在SDK版本5.8.7及以上已经提供。

接口介绍

设置是否获取用户信息的开关,此方法也需要在SDK初始化之前调用

  /**
 If set to YES, the server will not display personalized ads based on the user's personal information
 When receiving the user's request, and will not synchronize the user's information to other third-party partners.
 Default is NO
 */
@property (nonatomic, assign) BOOL doNotTrackStatus;

示例代码

[[MTGSDK sharedInstance] setDoNotTrackStatus:NO];

ChangeLog

版本号 changeLog 发布时间
6.7.2 性能优化 2020.12.10
6.7.1 修复NativeVideo bug 2020.12.09
6.7.0 1、适配 ios14 放大视图模式 2、Bug fixed 2020.12.02
6.6.9 基于sonar服务扫描后给出的优化建议,进行了代码优化 2020.11.18
6.6.8 移除手机剩余内存、设备用户名等信息 2020.11.13
6.6.6 SDK 添加识别5G网络状态 2020.10.30
6.6.5 Bug fixed 2020.10.22
6.6.3 优化开屏广告 show 方法对开发者传入参数的限制 2020.09.25
6.6.2 1.新增支持开发者获取requestId 2.SDK优化 2020.09.23
6.6.1 新增setting 备用域名 2020.09.17
6.6.0 1.优化GDPR,删除GDPR弹窗;2.优化支持iOS14,删除skoverlay;3.bug fixed. 2020.09.10
6.5.0 适配 iOS 14,支持 SKNetwork 归因 2020.09.03
6.4.1 1、性能优化 2、bug fixed 2020.08.26
6.4.0 1.RV 新增Reward Plus,奖励优化 2.NV支持播放完成回调 3.bid framework add reward plus 4.bug fixed 2020.08.13
6.3.7 修复某些场景下偶现因丢失onVideoAdDismissed回调中的reward信息导致的崩溃 2020.08.04
6.3.5 修复广告播放完毕后无法恢复应用声音问题 2020.07.16
6.3.4 Banner Header Bidding模式取消自动刷新功能 2020.07.08
6.3.3 1.升级GDPR 2.更新OMSDK(彻底移除OMSDK相关的以UIWebView命名的方法名) 3.MTGSDK不再支持XCode11以下版本archive 4.Bug fixed. 2020.06.24
6.3.2 1.优化sdk日志上报 2.Bug fixed 2020.05.29
6.3.1 1.新增原生自动渲染广告类;2.Bug fixed 2020.05.26
6.2.0 新增Placement id 2020.04.16
6.1.3 bug 修复 2020.04.14
6.1.2 兼容穿山甲 WKWebView bug 2020.03.19
6.1.1 优化Header Bidding buyeruid参数 2020.03.13
6.1.0 修复5.9.0以上版本某特定场景下请求失败 2020.03.09
6.0.0 1、H5模板优化;2、打包 sdk 的 xcode 升级为9.2;3、新增支持 Splash 类型广告 2020.03.03
5.9.0 1.IV新增奖励模式; 2.InterstitialVideo、RewardVideo、Interactive新增计时设置 2020.02.14
5.8.8 1.Banner广告新增关闭回调API; 2.开发者提前销毁BannerAdView,内存释放优化 2020.01.09
5.8.7 1. 为CCPA法案,MTGSDK类新增开发者设置doNotTrackStatu; 2. Bid接口添加idfv参数上报 2019.12.26
5.8.6 1.Banner形式支持外部DSP流量;2.Banner内存性能优化(web及时释放) 2019.12.20
5.8.5 1.视频资源下载优化 2019.12.12
5.8.4 1.移除UIWebView 2.兼容iOS 13.1 sk和xcode11.1 2019.11.11
5.8.3 1.banner支持header bidding 2.bid framework新增bid request API 2019.10.17
5.8.2 1.SDK优化 2019.10.12
5.8.1 1.InterstitialVideo优化 2019.10.02
5.8.0 1.集成Open Measurement SDK 2.banner支持mraid expend 2019.09.26
5.7.1 1.banner接口优化 2019.09.16
5.7.0 1.ios 13 适配,SDK最低支持iOS8 2019.09.06
5.6.1 1.逻辑优化 2019.08.30
5.6.0 1.新增banner广告类型 2019.08.27
5.5.3 1.修正header bidding的异常 2019.07.24
5.5.2 1.支持Marid协议 2019.07.18
5.4.2 1.性能优化 2.新增Head-bidding功能 2019.06.13
5.3.3 1.性能优化 2019.05.08
5.3.2 1.storekit优化 2.激励视频和插屏视频新增onVideoAdDidClosed 回调 2019.04.28
5.3.1 移除定位相关代码 2019.04.19
5.3.0 1.storekit优化 2.解决已知的一些bug 2019.04.10
5.2.0 1.优化了RV和IV广告的逻辑 2019.03.22
5.1.0 1.Nativevideo功能优化 2019.03.12
5.0.0 1.性能优化 2019.03.06
4.9.4 1.修复bug 2019.02.26
4.9.3 1.性能优化 2019.02.22
4.9.2 1.修复bug 2019.02.20
4.9.1 1.修复bug 2019.01.13
4.9.0 1.新增AdchoiceView 2019.01.10
4.8.0 1.修复bug 2018.12.08
4.7.0 1.修复bug 2018.10.23
4.5.0 1.新增视频广告请求返回回调接口 2018.9.18
4.4.0 1.修复主要的crash 2018.9.13
回到顶部