给自己的应用添加iAd广告之一
来源:互联网 发布:java 文件名带点 编辑:程序博客网 时间:2024/06/05 15:58
在这里,我先给大家介绍以下如何添加iAd广告,当然了,在这一讲,我先给大家介绍的是如何用代码实现添加iAd的效果,接下来,我会接续说说如何真正在我们应用里在发布时能用到。
先给自己的项目添加iAd.framework库
接着在头文件中添加下面代码:
#import <UIKit/UIKit.h>#import <iAd/iAd.h>@interface iAdsDemoViewController : UIViewController <ADBannerViewDelegate> {ADBannerView *adView;}@end
在实现里添加如下代码:
//// iAdsDemoViewController.m// iAdsDemo//// Created by gao wei on 10-6-12.// Copyright __MyCompanyName__ 2010. All rights reserved.//#import "iAdsDemoViewController.h"@implementation iAdsDemoViewController- (void)viewDidLoad {//竖屏adView = [[ADBannerView alloc] initWithFrame:CGRectZero];adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait; //adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;//横屏是用这个[self.view addSubview:adView];adView.delegate = self;adView.hidden = YES;adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil]; [super viewDidLoad];}- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{NSLog(@"should begin");return YES;}- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(@"did finish");}- (void)bannerViewDidLoadAd:(ADBannerView *)banner{NSLog(@"%d",adView.bannerLoaded);adView.hidden = NO;NSLog(@"did load");}- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{NSLog(@"error:%@",error);}- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{NSLog(@"rotate");//adView.frame = CGRectZero; if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)){adView.currentContentSizeIdentifier =ADBannerContentSizeIdentifierLandscape;adView.frame = CGRectZero;} else{ adView.currentContentSizeIdentifier =ADBannerContentSizeIdentifierPortrait;adView.frame = CGRectZero;}}// Override to allow orientations other than the default portrait orientation.- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { // Return YES for supported orientations return YES;}- (void)didReceiveMemoryWarning {// Releases the view if it doesn't have a superview. [super didReceiveMemoryWarning];// Release any cached data, images, etc that aren't in use.}- (void)viewDidUnload {// Release any retained subviews of the main view.// e.g. self.myOutlet = nil;}- (void)dealloc { [super dealloc];}@end
出现的效果图,如下:
例子下载在这里:http://download.csdn.net/detail/comeontom/4350668
- 给自己的应用添加iAd广告之一
- 如何在程序中添加iAd广告
- 如何在程序中添加iAd广告
- iOS开发用swift添加iAd广告
- Android-往自己的应用添加广告 赚钱第一步
- 如何在自己开发的android应用中添加广告
- 苹果的iAd广告概念解释
- 如何给自己的手机应用添加Google Analysis
- 给自己的博客做个广告
- 给自己的博客打一个广告
- 分步示意如何在iPhone应用中植入iAd广告
- iOS:集成iAd广告
- 给自己做个广告
- 给自己做个广告
- 添加VivePort应用 广告
- iOS 广告平台 iAD整合
- 给自己的BLOG添加计数器
- 如何给自己的blog添加功能
- SqlServer之Convert 函数应用格式化日期
- hibernate 二级缓存的说明和配置
- 常见视频文件格式详解
- text1.cpp
- hibernate3.5和spring结合使用annotation时onetomany的bug
- 给自己的应用添加iAd广告之一
- text2.cpp
- android之利用SQLite数据库实现登陆和注册
- FFmpeg编译详解
- 更改文件编码
- 获取文件的编码
- 高端内存与低端内存
- 转一篇我以前写的关于c语言的文章
- EASYSIZE Macro