6

i am trying to inset an iad banner at the bottom of my app but keep getting errors after following tutorials. code as follows.

@interface DMKHomeViewController (UIViewcontroller ) <ADBannerViewDelegate>{

}
@end

@implementation DMKHomeViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

-(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];

}

i keep getting the following error * Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ADBannerView' * First throw call stack:

MikeAsp
  • 147
  • 1
  • 12
  • 1
    possible duplicate of [iAd Banner is not working](http://stackoverflow.com/questions/12267770/iad-banner-is-not-working) – BB9z Apr 18 '15 at 09:24
  • @MikeAsp Hey bud mind marking my answer as the selected one? Thanks in advance. Cheers. – serge-k Sep 17 '15 at 16:29

2 Answers2

20

Please make sure that you have added the "iAd.framework"...

To do this go to the "App. Target", "General" and scroll down until you see "Linked Frameworks and Libraries". Hit "+" and select the iAd framework. See screen captures below...

App. Target -> General

'+' to add, search for iAd

serge-k
  • 3,394
  • 2
  • 24
  • 55
  • In my case, this is the correct answer. I decided to include an adBannerView inside a nib, but forgot to import the framework into my project and do this. – Coach Roebuck May 16 '16 at 15:11
  • @CoachRoebuck Hey! Just saw this. I am glad that this helped you! It is hard to keep track of all the frameworks, especially in a big project... So easy to forget. – serge-k Jul 07 '16 at 00:09
0

You have not created object of AdBannerview..

First, create object for banner view and set delegate for it.

-(void)ViewDidLoad
{
   [self createBannerView];
}
- (void)createBannerView {

  Class cls = NSClassFromString(@"ADBannerView");
  if (cls) {
    ADBannerView *adView = [[cls alloc] initWithFrame:CGRectZero];


    // Set the current size based on device orientation
    adView.currentContentSizeIdentifier = ADBannerContentSizeIdentifier320x50;
    adView.delegate = self;

    adView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin |
                              UIViewAutoresizingFlexibleRightMargin;

    // Set initial frame to be offscreen
    CGRect bannerFrame =adView.frame;
    bannerFrame.origin.y = self.view.frame.size.height;
    adView.frame = bannerFrame;

    self.bannerView = adView;
    [self.view addSubview:adView];
    [adView release];
  }
}
Bhoomi Jagani
  • 2,413
  • 18
  • 24
  • no that didnt work either ADBannerContentSizeIdentifier is depreciated – MikeAsp Jun 06 '14 at 12:44
  • First you create object and set delegate...without writing first ADBannerContentSizeIdentifier and check and run........and for more detail..http://useyourloaf.com/blog/2010/09/16/placing-iad-banners-at-the-top-of-a-table-view.html see this tutorial in more detail... – Bhoomi Jagani Jun 06 '14 at 12:48