1
votes

I have a tab based application. I have created an iAd object in app delegate class and using it in my three view controller class. It's working good on second tab's screen and third tab's screen. On second tab there is a table view, when clicking the row of that table view i navigate to the new view where i have used the same code for iAd. On clicking the iAd, iAd screen opens in landscape mode and when closing the screen becomes black and log the following.

[ADHostWindowController supportsOrientation:]: message sent to deallocated instance 0x100bc740

I created the object in app delegate like this:

self.bannerView = [[ADBannerView alloc]init];
[self.bannerView setDelegate:self];

I'm adding banner in view controllers like this:

[[[self appdelegate] bannerView] setFrame:CGRectMake(0, hightofView-180, 768, 66)]

All my view controllers are in portrait but iAds always open in landscape mode. This is working in iOs 6, but not with iOS 5 on iPad. How do I fix this?

2

2 Answers

1
votes

My guess your problem is not related to iAds but rather to memory issues. It seems that an object of class kind ADHostWindowController is being deallocated prematurely.

My advice would be to make sure that ADHostWindowController is not released i.e (retainCount>=1) before supportsOrientation: is called to it. (which is definitely after the iAd opens).

For diagnosis: Try logging the retain count of that ADHostWindowController (then maybe retaining it one more time) before opening an iAd and see what happens.

1
votes

Take a look at TabbleBanner code in iAd sample from Apple: https://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html

I don't investigate it in detail, but you need to follow the Apple iAd guide:https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/BannerAdvertisements/BannerAdvertisements.html

To create a ADBanner, in each UIViewController, add one to self.view

@property (strong,nonatomic) ADBannerView *bannerView;
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self createADBanner];
}

- (void)createADBanner{
    self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
    self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
    [self.bannerView setDelegate:self];
    [self.view addSubview:self.bannerView];
}

For beginning, you need to modify bannerView size and setCenter if need to place it at top or bottom.

- (void)viewDidLayoutSubviewsj{
    if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
        self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
        self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
    } else {
        self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
    }
}

And do the same when rotate:

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
        self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
    } else {
        self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
        self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
    }
}