How to add iAd to PhoneGap app: (Este post está em inglês para ajudar os desenvolvedores PhoneGap em todo mundo)
Step 1)
Modify the following function in yourAppDelegate.m:
From:
-(void)webViewDidFinishLoad:(UIWebView *)theWebView
{return[ super webViewDidFinishLoad:theWebView ];
}
To:
-(void)webViewDidFinishLoad:(UIWebView *)theWebView
{
bannerIsVisible =YES;
ADBannerView *adView =[[ADBannerView alloc] initWithFrame:CGRectZero];
adView.frame = CGRectMake(0, 410, 320, 50); // if you want the banner to be on top of the screen remove this line
adView.delegate = self;
adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
[theWebView addSubview:adView];
return[ super webViewDidFinishLoad:theWebView ];
}
Add the following methods before the @end in yourAppDelegate.m
-(void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError*)error
{if(bannerIsVisible){[UIView beginAnimations:@"animateAdBannerOff" context:NULL];
// assumes the banner view is at the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, 50); // if the banner is on top of the screen use -50[UIView commitAnimations];
bannerIsVisible =NO;
}}-(void)bannerViewDidLoadAd:(ADBannerView *)banner
{if(!bannerIsVisible){[UIView beginAnimations:@"animateAdBannerOn" context:NULL];
// assumes the banner view is offset -50 pixels so that it is not visible.
banner.frame = CGRectOffset(banner.frame, 0, -50); // if the banner is on top of the screen use 50[UIView commitAnimations];
bannerIsVisible =YES;
}}-(BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave
{
NSLog(@"Banner view is beginning an ad action");
BOOL shouldExecuteAction =YES; // your application implements this method if you want it not fixedif(!willLeave && shouldExecuteAction){// insert code here to suspend any services that might conflict with the advertisement}return shouldExecuteAction;
}
Step 4:
Add the iAd Framework to the list of Frameworks of your project.
Ready!
Don’t forget to enable iAds when you upload your app.
iad的广告大家可以自己定义,用iad Js 但是app的广告效果可能不及国内的一些厂商,请大家注意了,另外lz的app广告效果很可怜,大伙能不做广告尽量不要用了。。。。。。原文:http://www.zeletron.com.br/2010/07/adding-iad-in-phonegap-apps.htmlHow to add iAd to PhoneGap app: