iAd的横幅不工作(iAd Banner is not working)

2019-06-27 19:16发布

我想在我的应用获取的一面旗帜,但因为我加的旗帜,应用程序将无法启动。

我得到一个错误说:

终止应用程序由于未捕获的异常“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;
     }
}

你认为是错的?

Answer 1:

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



Answer 2:

把这个代码:

#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


文章来源: iAd Banner is not working