Question

I'm use the following code to add banner:

- (void) addBunner {
    CGRect frame = CGRectMake(0.0,
                              self.view.frame.size.height-50.0,
                              320.0,
                              50.0);

    UIWindow* window = [UIApplication sharedApplication].keyWindow;
    if (!window) {
        window = [[UIApplication sharedApplication].windows objectAtIndex:0];
    }

    ADBannerView *adView = [[ADBannerView alloc] initWithFrame:frame];

    adView.delegate=self;    
    [window addSubview:adView];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self addBunner];
}

iAd.framework is added.

App is crashing without any messages in log. Where is a problem?

Was it helpful?

Solution

The app is crashing because you are adding banner in window.

REASON : ADBannerView must be part of a view hierarchy managed by a UIViewController.

So add banner in UIViewController.

OTHER TIPS

It is not the best way to manage iAD in your application. As others Class, there are a lot of method to implement, which responds to iAD Delegate, for adding iAD Banner to App.

I suggest to read Apple Doc before using it - Apple iAD Documentation

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top