我无法实现ADBannerView及其委托协议。
我在我的视图类中实现了以下代码(也使视图符合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];
然后我为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
最终会出现横幅,但控制台会继续抛出以下类型的错误:
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}
并且委托函数没有做任何事情,所以根本没有NSLog。显然没有抓住错误。
我很难过。我想我在视图和委托中的Adbanner视图调用的链接中遗漏了一些东西。不知道怎么做或出了什么问题。
有任何帮助吗?提前谢谢。
杰森
答案 0 :(得分:9)
您之所以告诉 AdBannerView 您是其委托,但您从未将其放在您的实施文件中。您的实现文件应如下所示(请注意@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
此外,您不应该将您的班级命名为 ADBannerViewDelegate 。您的班级应该是 ADBannerView 的代表(回复它),但不能以其命名。
答案 1 :(得分:4)
我使用本教程在我的应用程序中成功集成了iAd:
http://www.raywenderlich.com/1371/how-to-integrate-iad-into-your-iphone-app
也可以帮到你。
答案 2 :(得分:2)
您不会尝试实现名为ADBannerViewDelegate
的类,而是将这些方法放在视图类的实现中。
(如果您实际上将您的视图类命名为“ADBannerViewDelegate”,请不要。这令人困惑。)
答案 3 :(得分:1)
对我而言,它是目标和设备,我在4.3模拟器和我的ipad 2上运行它但应用程序是用于iphone 5.1,当我更改目标时全部都是游泳
答案 4 :(得分:1)
你可以使用这个非常有用的链接