当前位置: 首页 > news >正文

给自己的应用添加iAd广告之一

在这里,我先给大家介绍以下如何添加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

相关文章:

  • virsh查看迁移信息的两个命令
  • 【iOS-Cocos2d游戏开发】触屏事件处理机制
  • 迷宫里的动态规划应用
  • Django学习手册 - cookie / session
  • We are unable to complete the review of your app since one or more of your In App Purchases have not
  • IOS内存管理
  • gerrit + ldap + phpldapadmin docker部署
  • 【编程之美】2.1 - 求二进制数中1的个数
  • JavaScript中数组的排序方法:1.冒泡排序 2.选择排序
  • js计算页面加载时间
  • Solium代码测试框架
  • 迎接第五次工业革命浪潮,不当纳米知识文盲
  • 12-单表查询
  • Microsoft Component Designer 设计组件一例
  • 百度云高速下载Pandownload
  • 【EOS】Cleos基础
  • Git同步原始仓库到Fork仓库中
  • JavaScript标准库系列——Math对象和Date对象(二)
  • JavaScript函数式编程(一)
  • Java知识点总结(JavaIO-打印流)
  • Netty+SpringBoot+FastDFS+Html5实现聊天App(六)
  • Spring Boot快速入门(一):Hello Spring Boot
  • SQL 难点解决:记录的引用
  • vue学习系列(二)vue-cli
  • 解析 Webpack中import、require、按需加载的执行过程
  • 每个JavaScript开发人员应阅读的书【1】 - JavaScript: The Good Parts
  • 日剧·日综资源集合(建议收藏)
  • 如何抓住下一波零售风口?看RPA玩转零售自动化
  • 使用SAX解析XML
  • SAP CRM里Lead通过工作流自动创建Opportunity的原理讲解 ...
  • Spark2.4.0源码分析之WorldCount 默认shuffling并行度为200(九) ...
  • 扩展资源服务器解决oauth2 性能瓶颈
  • 数据可视化之下发图实践
  • ​​​​​​​sokit v1.3抓手机应用socket数据包: Socket是传输控制层协议,WebSocket是应用层协议。
  • (13)Latex:基于ΤΕΧ的自动排版系统——写论文必备
  • (32位汇编 五)mov/add/sub/and/or/xor/not
  • (done) ROC曲线 和 AUC值 分别是什么?
  • (第9篇)大数据的的超级应用——数据挖掘-推荐系统
  • (排序详解之 堆排序)
  • (十八)用JAVA编写MP3解码器——迷你播放器
  • (一)pytest自动化测试框架之生成测试报告(mac系统)
  • (一)搭建springboot+vue前后端分离项目--前端vue搭建
  • (转)使用VMware vSphere标准交换机设置网络连接
  • .[backups@airmail.cc].faust勒索病毒的最新威胁:如何恢复您的数据?
  • .java 指数平滑_转载:二次指数平滑法求预测值的Java代码
  • .net framework 4.0中如何 输出 form 的name属性。
  • .NET框架
  • .net专家(张羿专栏)
  • /bin/bash^M: bad interpreter: No such file or directory
  • @Transactional 详解
  • @zabbix数据库历史与趋势数据占用优化(mysql存储查询)
  • [ 蓝桥杯Web真题 ]-布局切换
  • [20170705]lsnrctl status LISTENER_SCAN1
  • [ASP]青辰网络考试管理系统NES X3.5
  • [BT]BUUCTF刷题第9天(3.27)