iAd Banner无效

时间:2012-09-04 16:33:47

标签: ios iad adbannerview

我正在尝试在我的应用中添加横幅,但由于我添加了横幅广告,因此该应用无法启动。

我收到错误说:

  

由于未捕获的异常'NSInvalidUnarchiveOperationException'而终止应用程序,原因:'无法实例化名为ADBannerView的类'

.h文件中的代码:

#import <iAd/iAd.h>

@interface FirstViewController : UIViewController <ADBannerViewDelegate>
{
    ADBannerView *banner;  
}
@property (nonatomic,assign) BOOL bannerIsVisible;
@property (nonatomic,retain) IBOutlet ADBannerView *banner;

.m文件中的代码:

@synthesize banner, bannerIsVisible;

-(void)bannerViewDidLoad: (ADBannerView *)abanner
{
     if(!self.bannerIsVisible)
     {
         [UIView beginAnimations:@"animatedAdBannerOn" context:NULL];
         banner.frame=CGRectOffset(banner.frame, 0.0, 50.0);
         [UIView commitAnimations];
         self.bannerIsVisible=YES;
     }
}
-(void)bannerView:(ADBannerView *)aBanner
{
     if(!self.bannerIsVisible)
     {
         [UIView beginAnimations:@"animatedAdBannerOff" context:NULL];
          banner.frame=CGRectOffset(banner.frame, 0.0, -320.0);
         [UIView commitAnimations];
         self.bannerIsVisible=NO;
     }
}

你认为错在哪里?

2 个答案:

答案 0 :(得分:19)

您必须将iAd.framework添加到项目中。

答案 1 :(得分:1)

拿这段代码:

#import <iAd/iAd.h>

@interface ViewController : UIViewController <ADBannerViewDelegate> {
}
@end

.m文件:

@implementation ViewController

-(void)bannerViewDidLoadAd:(ADBannerView *)banner {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:1];
    [UIView commitAnimations];
}

- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:1];
    [banner setAlpha:0];
    [UIView commitAnimations];
}
@end