Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make iAd to be viewed globally in my app?

I am developing an application where i have to show iAds in all the pages of my application.. I created a subclass of UIView where i am initializing the the ADBannerView and its delegate methods.

But now if I add it in window in AppDelegate class it is giving me following error at run time "ADBannerView must be part of a view hierarchy managed by a UIViewController"..

I think this mean that I can use ADBanner only in UIViewController's subclass file??

if so then how can I make it global??

Thanks in Advance Shreya

like image 636
Shreya Avatar asked Apr 02 '12 07:04

Shreya


1 Answers

In AppDelegate class you can make a shared object.

- (ADBannerView *) sharedBannerView
{
    if (_sharedBannerView == nil)
    {
        Class classAdBannerView = NSClassFromString(@"ADBannerView");

        if (classAdBannerView != nil)
        {
            _sharedBannerView = [[classAdBannerView alloc] initWithFrame:CGRectMake(0, 480, 320, 50)];

            // pre 4.2 doesn't have the new AdBannerSize constants. 
            if (&ADBannerContentSizeIdentifierPortrait != NULL)
            {
                [_sharedBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:ADBannerContentSizeIdentifierPortrait, ADBannerContentSizeIdentifierLandscape, nil]];            
            }
            else
            {  
                [_sharedBannerView setRequiredContentSizeIdentifiers:[NSSet setWithObjects:ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil]];            
            }
        }   
    }

    ((ADBannerView *)_sharedBannerView).backgroundColor = [UIColor whiteColor];

    return _sharedBannerView;
}

And add this shared object to the view wherever you need to display iAds. Hope you get it.

like image 97
Neelam Verma Avatar answered Oct 17 '22 20:10

Neelam Verma