Cocoa Dev
Cocoa Dev

Reputation: 9541

iOS 6 and iAds giving too many warnings

Here is my iAd code and I'm getting warnings about

setRequiredContentSizeIdentifiers - deprecated in iOS 6
ADBannerContentSizeIdentifier320x50 - deprecated in iOS 4.2
ADBannerContentSizeIdentifier480x32 - deprecated in iOS 4.2
setCurrentContentSizeIdentifier - deprecated in iOS 6
ADBannerContentSizeIdentifier480x32 - deprecated in iOS 4.2

How do I fix this so there are no warnings.

- (int)getBannerHeight:(UIDeviceOrientation)orientation
{
    if (UIInterfaceOrientationIsLandscape(orientation)) {
        return 32;
    } else {
        return 50;
    }
}

- (int)getBannerHeight
{
    return [self getBannerHeight:[UIDevice currentDevice].orientation];
}

- (void)createAdBannerView
{
    Class classAdBannerView = NSClassFromString(@"ADBannerView");
    if (classAdBannerView != nil) {
        self->adView = [[classAdBannerView alloc]
                              initWithFrame:CGRectZero];
        [adView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:
                                                          ADBannerContentSizeIdentifier320x50,
                                                          ADBannerContentSizeIdentifier480x32, nil]];
        if (UIInterfaceOrientationIsLandscape([UIDevice currentDevice].orientation)) {
            [adView setCurrentContentSizeIdentifier:
             ADBannerContentSizeIdentifier480x32];
        } else {
            [adView setCurrentContentSizeIdentifier:
             ADBannerContentSizeIdentifier320x50];
        }
        [adView setFrame:CGRectOffset([adView frame], 0,
                                             -[self getBannerHeight])];
        [adView setDelegate:self];

        [self.view addSubview:adView];        
    }
}

- (void)fixupAdView:(UIInterfaceOrientation)toInterfaceOrientation
{
    if (adView != nil) {
        if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
            [adView setCurrentContentSizeIdentifier:
             ADBannerContentSizeIdentifier480x32];
        } else {
            [adView setCurrentContentSizeIdentifier:
             ADBannerContentSizeIdentifier320x50];
        }
        [UIView beginAnimations:@"fixupViews" context:nil];
        if (bannerIsVisible) {
            CGRect adBannerViewFrame = [adView frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y = 0;
            [adView setFrame:adBannerViewFrame];
            CGRect contentViewFrame = _contentView.frame;
            contentViewFrame.origin.y =
            [self getBannerHeight:toInterfaceOrientation];
            contentViewFrame.size.height = self.view.frame.size.height -
            [self getBannerHeight:toInterfaceOrientation];
            _contentView.frame = contentViewFrame;
        } else {
            CGRect adBannerViewFrame = [adView frame];
            adBannerViewFrame.origin.x = 0;
            adBannerViewFrame.origin.y =
            -[self getBannerHeight:toInterfaceOrientation];
            [adView setFrame:adBannerViewFrame];
            CGRect contentViewFrame = _contentView.frame;
            contentViewFrame.origin.y = 0;
            contentViewFrame.size.height = self.view.frame.size.height;
            _contentView.frame = contentViewFrame;
        }
        [UIView commitAnimations];
    }
}

Upvotes: 3

Views: 3326

Answers (1)

Macmade
Macmade

Reputation: 53960

You are using deprecated methods/symbols.

Deprecation means the methods/symbols are still here, and will usually still work, but they may be removed on future iOS versions.

The official documentation always list the deprecated methods/symbols, and usually provides the new ones.

So I hate to say this, as an answer, but just read the doc.

Warnings about iOS 6 are not too bad, as iOS 6 is pretty new.
But also fix them if you can. What is done is done.

But it seems you are also using methods/symbols that were deprecated on iOS 4.2!
This is actually a concern. iOS 4 support is currently dropping, so your actual code might not work for long.

So read the doc (again), learn about the new methods, and fix your code.

For instance:

ADBannerContentSizeIdentifier320x50 - deprecated in iOS 4.2

In the documentation, you can read the following:

ADBannerContentSizeIdentifier320x50 Indicates that the banner view is 320 points by 50 points in size. This size is used on iPhone for portrait advertisements. (Deprecated. Use ADBannerContentSizeIdentifierPortrait instead.) Available in iOS 4.0 and later. Deprecated in iOS 4.2. Declared in ADBannerView_Deprecated.h.

So instead of ADBannerContentSizeIdentifier320x50, simply use ADBannerContentSizeIdentifierPortrait.
Same for ADBannerContentSizeIdentifier480x32. Use ADBannerContentSizeIdentifierLandscape instead.

You'll then be safe, and you'll no longer have a warning about this.

Then simply do the same for the other symbols.

EDIT


As stated on your comment, ADBannerContentSizeIdentifierPortrait and ADBannerContentSizeIdentifierLandscape are also deprecated on iOS 6.

This is related to the deprecation of setCurrentContentSizeIdentifier and setRequiredContentSizeIdentifiers.

Apple recommends not to use that approach anymore, and use the auto-resizing capabilities of iOS.

Upvotes: 8

Related Questions