Question

I am trying to construct a iOS universal application template that transparently handles iAds & screen rotations.

i.e. instead of using UIViewController for each new project, I will instead use my own iAdVC (which will subclass UIViewController). This will seamlessly handle the iAds, and hand over the remaining window space to the user.

I'm trying this: view controller contains uberView which contains {adView, content view}.

whenever an ad appears and disappears, both {adView, content view} will animate:

  • content view squashing the frame's top down slightly to make space for my iAd,
  • and fade in the ad along the top at the same time.

    also, every time the device rotates, the views need to be resized.

I'm getting really dumb problem, when the first Ad gets served, I place it at the top of the screen and squash the remaining content frame to make space for it.

but if I change the content view's frame, I can no longer click the ad. and if I don't, the content view doesn't fit in its window,

http://d.pr/ZyQG

- (void) bannerViewDidLoadAd: (ADBannerView *) banner 
{   
    bool isLandscape = UIInterfaceOrientationIsLandscape( self.interfaceOrientation );
    NSString * contentSize = isLandscape ? ADBannerContentSizeIdentifierLandscape : ADBannerContentSizeIdentifierPortrait ;

    [self.adBannerView setCurrentContentSizeIdentifier: contentSize];

    CGSize bannerSize = [ADBannerView sizeFromBannerContentSizeIdentifier: contentSize];
    self.adBannerView.frame = CGRectMake(0, 0, bannerSize.width, bannerSize.height);

    // resize content frame & fade ad in        
    CGRect newContentFrame = uberView.bounds;
    newContentFrame.size.height -= bannerSize.height;
    newContentFrame.origin.y += bannerSize.height;   

    NSLog(@"%@", NSStringFromCGRect(newContentFrame)); // {{0, 50}, {320, 430}}
    if (1) // 0 works
        self.contentView.frame = newContentFrame; // NOW CANT CLICK AD
}
Was it helpful?

Solution 2

https://github.com/p-i-/iAdUniversalTemplate

This is a XIB-less universal-app iAd-rotatey-enabled template, which requires a minimum target of iOS 4.2

It took a lot of thrashing around, namely iAd -- cannot click banner

But it is in good shape now.

OTHER TIPS

Minimum deployment target
The first question is: what is a sensible minimum deployment target? Seeing as this is a universal application, we should use iOS 4.2, as this is the first version that is unified between iPhone and iPad.

Question arises: what fraction of ad-clicking customers do we lose? eg is it worth supporting 4.0 just to get an extra 15% of customers?

http://insights.chitika.com/2011/ios-update-ipads-iphones-running-high-rate-of-ios-4/ shows that you still pick up 80% of ad-clicking customers if you select 4.2.

Obviously this fraction is going to increase with time, so I'm going for the easiest coding option rather than trying to squeeze every last penny out of the market.

This has an added benefit:

// Supported sizes of banner ads available from ad server. Dimensions are in points, not pixels.
// The dimensions are part of the value names to assist with design-time planning for view layout.
extern NSString * const ADBannerContentSizeIdentifier320x50 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_4_0,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifier480x32 __OSX_AVAILABLE_BUT_DEPRECATED(__MAC_NA,__MAC_NA,__IPHONE_4_0,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifierPortrait __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);
extern NSString * const ADBannerContentSizeIdentifierLandscape __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_4_2);

ie We can use the new symbols, which are generic (ie work for both iPhone and iPad)

strPortrait = ADBannerContentSizeIdentifierPortrait; // ADBannerContentSizeIdentifier320x50;
strLandscape = ADBannerContentSizeIdentifierLandscape; // ADBannerContentSizeIdentifier480x32;

The banner can be either horizontal or vertical, so you need to load in:

[self.adBannerView setRequiredContentSizeIdentifiers:
    [NSSet setWithObjects: strPortrait, strLandscape, nil]
];  

Then when the screen turns 90°, the AdBannerView needs to be told:

[self.adBannerView setCurrentContentSizeIdentifier: isLandscape ? strLandscape : strPortrait ];

Directly after this is set, you can query self.adBannerView.frame and get the new size

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