phonegap结合iad

iad的广告大家可以自己定义,用iad Js 但是app的广告效果可能不及国内的一些厂商,请大家注意了,另外lz的app广告效果很可怜,大伙能不做广告尽量不要用了。。。。。。

原文:http://www.zeletron.com.br/2010/07/adding-iad-in-phonegap-apps.html


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 ];
}

Step 2:

Modify the yourAppDelegate.h:

From:

@interface Desafio3x3AppDelegate : PhoneGapDelegate {
}

To:

#import "iAd/iAd.h"
 
@interface Desafio3x3AppDelegate : PhoneGapDelegate <ADBannerViewDelegate> {
	BOOL bannerIsVisible;
}

Step 3:

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 fixed
    if (!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.


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值