Bison教你1分钟集成百度移动SSP启动广告

Baidu SSP

"让你的APP集成百度移动SSP启动广告,增加收入"

Bison

1
冰之依韩版女装(程序媛福利)


自己的app最近要上架啦,免费的app,琢磨着怎么把那开发者99美元赚回来好呢?
感觉最简单的就是在自己的app里面增加广告来赚回,但因我是一个完美主义者,
不喜欢那种广告满天飞,玩着玩着,就跑出个插播广告来,影响用户体验度的同时,
也影响app的美观,这是我无法容忍的。进入俩难当中,随便找了下百度的移动SSP
百度SSP的样式有很多种,对于我来说,开屏广告是最适合的,一来不会影响用户的
体验度,二来也不会影响app的整体美观。于是就定下来这个方案
下面让我们来看看怎么集成

百度SSP官网传送站

首先在百度SSP注册个账号,然后到应用管理里面新增一个移动应用,填好相关的资料
然后下载SDK,把下载的ios_api文件夹拉到我们自己的工程里面

##warning:iOS9适配说明:

1.在plist中,添加baidumobads到LSApplicationQueriesSchemes数组下. 注意:Xcode7.0 模拟器上会error:(null),真机上不会报错,这里错误可以忽略.

    <key>LSApplicationQueriesSchemes</key> <array>
    <string>baidumobads</string>
    </array>

2.ENABLE_BITCODE=YES. SDK已支持BITCODE,若不需要则直接设置为NO即可.

3.在plist中,在NSAppTransportSecurity下设置NSAllowsArbitraryLoads为true. 注: 在Xcode7.1请设置App Transport Security Settings下设置 Allow Arbitrary Loads 为true.

    <key>NSAppTransportSecurity</key> 
    <dict>
    <key>NSAllowsArbitraryLoads</key> 
    <true/>
    </dict>


4.SDK用到的.dylib 库在Xcode7都变成了.tbd后缀, 导入相应名字的库即可.

##然后添加Frameworks

QuartzCore.framework
Security.framework
AdSupport.framework
StoreKit.framework
libz.dylib
AudioToolbox.framework
CoreMotion.framework
MediaPlayer.framework
AVFoundation.framework
MessageUI.framework
CoreLocation.framework
CoreTelephony.framework
SystemConfiguration.framework
CoreGraphics.framework
WebKit.framework

##再编译参数设置

targets->BuildSettings->Other Linker Flags ->添加 -ObjC -lstdc++

配置到此结束了,下面在此我们只讲下百度SSP的开屏广告

AppDelegate中导入头文件
#import "BaiduMobAdSplashDelegate.h"
#import "BaiduMobAdSplash.h"
添加BaiduMobAdSplashDelegate代理

具体代码如下

.h文件

@property (strong, nonatomic) BaiduMobAdSplash *splash;

@property (strong, nonatomic) UIView *customSplashView;

.m文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    //百度广告
    [self BaiDuNew];

    return YES;
}

- (void)BaiDuNew{

    [self.window makeKeyAndVisible];
    BaiduMobAdSplash	*splash	=	[[BaiduMobAdSplash	alloc]	init];
    splash.delegate	= self;
    //把在mssp.baidu.com上创建后获得的代码位id写到这里
    splash.AdUnitTag = @"2365464";
    splash.canSplashClick	=	YES;
    [splash	loadAndDisplayUsingKeyWindow:self.window];
    self.splash	= splash;

    //可以在customSplashView上显示包含icon的自定义开屏
    self.customSplashView = [[UIView alloc]initWithFrame:self.window.frame];
    self.customSplashView.backgroundColor = [UIColor whiteColor];
    [self.window addSubview:self.customSplashView];
    [self.window bringSubviewToFront:self.customSplashView];


    //在baiduSplashContainer用做上展现百度广告的容器,注意尺寸必须大于200*200,并且baiduSplashContainer需要全部在window内,同时开机画面不建议旋转
    CGFloat width = self.window.frame.size.width;
    CGFloat height= self.window.frame.size.height;
    UIView * baiduSplashContainer = [[UIView alloc]initWithFrame:CGRectMake(0, 0, width, height-100)];
    [self.customSplashView addSubview:baiduSplashContainer];

    UIImageView *iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"icon.png"]];
    [iconView setFrame:CGRectMake(width/2-70-40, height-90, 80, 80)];
    [self.customSplashView addSubview:iconView];

    UIImageView *logoView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"ITBlog.png"]];
    [logoView setFrame:CGRectMake(CGRectGetMaxX(iconView.frame)+40, height-90, 130, 50)];
    [self.customSplashView addSubview:logoView];

    UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(CGRectGetMinX(logoView.frame)-2, CGRectGetMaxY(logoView.frame), 130, 25)];
    label.font = [UIFont systemFontOfSize:13];
    label.textAlignment = NSTextAlignmentLeft;
    label.textColor = [UIColor lightGrayColor];
    label.text = @"自学iOS开发进阶首选";
    label.textAlignment = NSTextAlignmentCenter;
    [self.customSplashView addSubview:label];
    //在的baiduSplashContainer里展现百度广告
    [splash loadAndDisplayUsingContainerView:baiduSplashContainer];
}

- (NSString *)publisherId
{

    return @"ab17bd77";
}

/**
*  广告展示成功
*/
- (void)splashSuccessPresentScreen:(BaiduMobAdSplash *)splash
{
    NSLog(@"splashSuccessPresentScreen");
}

/**
*  广告展示失败
*/
- (void)splashlFailPresentScreen:(BaiduMobAdSplash *)splash withError:(BaiduMobFailReason) reason
{
    NSLog(@"splashlFailPresentScreen withError:%d",reason);
    //自定义开屏移除
    [self.customSplashView removeFromSuperview];
}

/**
*  广告展示结束
*/
- (void)splashDidDismissScreen:(BaiduMobAdSplash *)splash
{
    NSLog(@"splashDidDismissScreen");
    //自定义开屏移除
    [self.customSplashView removeFromSuperview];
}

/**
*  广告点击
*/
- (void)splashDidClicked:(BaiduMobAdSplash *)splash
{
    NSLog(@"splashDidClicked");
}


效果图如下

(PCGestureUnlock)

Demo—下载

博主app—下载

更多经验请点击

好文推荐:iOS开发内购全套图文教程

版权归©Bison所有 如需转载请保留原文超链接地址!否则后果自负!


分享文章