怎么集成优量汇(腾讯广告SDK)

通过cocoapods安装

pod "GDTMobSDK"

一.开屏广告

引入头文件

 #import "GDTSplashAd.h"

添加属性

@property (strong, nonatomic) GDTSplashAd *splash;

在启动时,加入下面的代码

- (void)addQQAd{

    GDTSplashAd *splash = [[GDTSplashAd alloc] initWithAppId:@"xxx" placementId:@"xxx"];
    splash.delegate = self; //设置代理
    //根据iPhone设备不同设置不同背景图
    splash.backgroundColor = [UIColor whiteColor];
    splash.fetchDelay = 5; //开发者可以设置开屏拉取时间,超时则放弃展示
    // 拉取并展示全屏开屏广告
    [splash loadAdAndShowInWindow:self.window];
    self.splash = splash;
    [self loadInterstitialAd];
}

遵守协议GDTSplashAdDelegate
实现代理方法

-(void)splashAdClosed:(GDTSplashAd *)splashAd
{
    NSLog(@"%s",__FUNCTION__);
    self.splash = nil;   
}

- (void)splashAdFailToPresent:(GDTSplashAd *)splashAd withError:(NSError *)error
{
    NSLog(@"%s%@",__FUNCTION__,error);
    self.splash = nil;
}

二、插屏广告

引入头文件

#import "GDTUnifiedInterstitialAd.h"

增加属性

@property (nonatomic, strong) GDTUnifiedInterstitialAd *interstitial;

加载插屏

- (void)loadQQChaPing{
    
    self.interstitial = [[GDTUnifiedInterstitialAd alloc] initWithAppId:@"xxx" placementId:@"xxx"];
    self.interstitial.delegate = self;
    [self.interstitial loadAd];
    
}

在合适的时机弹出插屏

[self.interstitial presentAdFromRootViewController:self];

遵守协议GDTUnifiedInterstitialAdDelegate
实现代理方法

- (void)unifiedInterstitialDidDismissScreen:(GDTUnifiedInterstitialAd *)unifiedInterstitial{
    [self.interstitial loadAd];
}

你可能感兴趣的:(iOS,iOS)