Integrate advertisements in iPhone programs, whether or not they can make money or not.
Refer to the following article:
Http://bees4honey.com/blog/tutorial/how-to-add-iad-banner-in-iphoneipad-app/
Refer to the integrating Iads into an iOS 4 iPad app (xcode 4) tutorial.
(1) Add the IAD framework
Link binary with libraries of build phases in the Project Settings, plus IAD. framework.
(2)
Drag an adbannerview in the xib Interface
(3) modify the. h file of viewcontroller
# Import <IAD/IAD. h>
Add Delegation
@ Interface myviewcontroller: uiviewcontroller <adbannerviewdelegate>
Add the output port
Iboutlet adbannerview * adview;
Bool bannerisvisible;
@ Property (nonatomic, retain) adbannerview * adview;
@ Property (nonatomic, assign) bool bannerisvisible;
(4) modify the. M file of viewcontroller
In the viewdidload method:
Adview. requiredcontentsizeidentifiers = [nsset setwithobject: adbannercontentsizeidentifierportrait];
Adview. currentcontentsizeidentifier = adbannercontentsizeidentifierportrait;
Adview. Delegate = self;
In the viewdidunload method:
Adview. Delegate = nil;
In addition:
To prevent iPhone network exceptions, IAD is a blank area when it cannot be displayed. you can do some work in these two methods.
-(Void) bannerviewdidloadad :( adbannerview *) banner
{
If (! Self. bannerisvisible)
{
[Uiview beginanimations: @ "animateadbanneron" context: NULL];
Banner. Frame = cgrectoffset (banner. Frame, 0,-100 );
[Uiview commitanimations];
Self. bannerisvisible = yes;
}
}
-(Void) bannerview :( adbannerview *) banner didfailtoreceiveadwitherror :( nserror *) Error
{
If (self. bannerisvisible)
{
[Uiview beginanimations: @ "animateadbanneroff" context: NULL];
Banner. Frame = cgrectoffset (banner. Frame, 0,100 );
[Uiview commitanimations];
Self. bannerisvisible = no;
}
}