简体   繁体   English

如何实现AdBannerview和ADBannerview委托

[英]how to implement AdBannerview and ADBannerview delegate

I am having trouble implementing ADBannerView and its delegate protocol. 我无法实现ADBannerView及其委托协议。

I implemented the following code in my view class (also made the view conform to the ADBannerViewDelegate protocol): 我在我的视图类中实现了以下代码(也使视图符合ADBannerViewDelegate协议):

//add iAds
ADBannerView *adView = [[ADBannerView alloc] initWithFrame: CGRectMake(0, 318, 320, 50)];
adView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil];
adView.delegate = self; 
//adView.delegate = ADBannerViewDelegate;
[self.view addSubview: adView];

then I created a class for the ADBannerViewDelegate, with the following .m 然后我为ADBannerViewDelegate创建了一个类,其中包含以下.m

//
//  ADBannerViewDelegate.m
//

#import "ADBannerViewDelegate.h"

@implementation ADBannerViewDelegate

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"bannerview did not receive any banner due to %@", error);}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(@"bannerview was selected");}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(@"banner was loaded");}

@end

the banners are eventually presented but the console keep throwing the following type of errors: 最终会显示横幅,但控制台会继续抛出以下类型的错误:

2011-02-27 15:00:54.108 app[31639:207] ADBannerView: Unhandled error (no delegate or delegate does not implement didFailToReceiveAdWithError:): Error Domain=ADErrorDomain Code=5 "The operation couldn’t be completed. Banner view is visible but does not have content" UserInfo=0x6356a40 {ADInternalErrorCode=5, NSLocalizedFailureReason=Banner view is visible but does not have content}

and the delegate functions are not doing anything , so no NSLog at all. 并且委托函数没有做任何事情,所以根本没有NSLog。 Obviously not catching the errors. 显然没有抓住错误。

I am stumped. 我很难过。 I guess I am missing something in the linkage of the Adbanner view calls in the view and the delegate. 我想我在视图和委托中的Adbanner视图调用的链接中遗漏了一些东西。 Not sure how to do it or what is wrong. 不知道该怎么做或出了什么问题。

Any help? 有帮助吗? Thanks in advance. 提前致谢。

Jason 贾森

The reason why is you told the AdBannerView that you are its delegate but you never put it in your implementation file. 你之所以告诉AdBannerView你是它的委托,但你从来没有把它放在你的实现文件中。 Your implementation file should look like this (notice the line with @implmentation ): 您的实现文件应如下所示(注意@implmentation的行):

//
//  ADBannerViewDelegate.m
//

#import "ADBannerViewDelegate.h"

@implementation ADBannerViewDelegate<ADBannerViewDelegate>

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error{
    NSLog(@"bannerview did not receive any banner due to %@", error);}

- (void)bannerViewActionDidFinish:(ADBannerView *)banner{NSLog(@"bannerview was selected");}

- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner willLeaveApplication:(BOOL)willLeave{return willLeave;}

- (void)bannerViewDidLoadAd:(ADBannerView *)banner {NSLog(@"banner was loaded");}

@end

And also you shouldn't name your class ADBannerViewDelegate . 而且你也不应该把你的班级命名为ADBannerViewDelegate Your class should be a delegate (respond to it) to ADBannerView but not be named after it. 您的类应该是ADBannerView的委托(响应它),但不能以它的名字命名。

i successfully integrated iAds in my app using this tutorial: 我使用本教程在我的应用程序中成功集成了iAd:
http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app
might help you too. 也可以帮到你。

You don't try to implement a class named ADBannerViewDelegate , you put those methods in the implementation for your view class. 您不会尝试实现名为ADBannerViewDelegate的类,而是将这些方法放在视图类的实现中。

(If you actually named your view class "ADBannerViewDelegate", don't. It's confusing.) (如果你实际上将你的视图类命名为“ADBannerViewDelegate”,那就不要了。这很令人困惑。)

对我来说它是目标和设备,我在4.3模拟器和我的ipad 2上运行它但是应用程序是用于iphone 5.1,当我改变目标时所有都是游泳的

you can Use this link its very helpful 你可以使用这个链接非常有帮助

http://codewithchris.com/iad-tutorial/ http://codewithchris.com/iad-tutorial/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM