百度移动SSP启动广告

来源:互联网 发布:广州汇丰软件 编辑:程序博客网 时间:2024/05/17 04:37

百度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

Foundation.framework

UIKit.framework

CoreMedia.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=[[BaiduMobAdSplashalloc]init];    splash.delegate= self;    //把在mssp.baidu.com上创建后获得的代码位id写到这里    splash.AdUnitTag = @"2365464";    splash.canSplashClick=YES;    [splashloadAndDisplayUsingKeyWindow: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");}

0 0
原创粉丝点击