10

I'm trying to get a banner in my app, but since I added the banner, the app won't start.

I get an error saying:

Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ADBannerView'

Code in .h file:

#import <iAd/iAd.h>

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

Code in .m file:

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

What do you think is wrong?

Pang
  • 9,564
  • 146
  • 81
  • 122
Mangy92
  • 621
  • 1
  • 10
  • 25

2 Answers2

19

You must add iAd.framework into your project.

lykant
  • 516
  • 4
  • 17
  • and also do self.canDisplayBanners = YES; – user2277872 Feb 16 '14 at 21:22
  • Nice example here: [31 Days of iOS: Day 29-Advertising with iAd](http://chrisrisner.com/31-Days-of-iOS--Day-29%E2%80%93Advertising-with-iAd) – leanne May 29 '14 at 19:31
  • @lykant Nice answer, I answered a similar question and threw in a few pictures, for those who care to take a look: http://stackoverflow.com/a/26172282/4018041 – serge-k Sep 17 '15 at 16:26
  • In Swift `import iAd` should be enough to trigger link with the framework but I still get the same exception. Any ideas? – Rivera Oct 29 '15 at 20:57
1

Take this code:

#import <iAd/iAd.h>

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

.m file:

@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
Pang
  • 9,564
  • 146
  • 81
  • 122
Maurice
  • 1,466
  • 1
  • 13
  • 33