How to make iAd to view globally in my application?

I am developing an application where I need to display iAds on all pages of my application. I created a subclass of UIView where I initialize the ADBannerView and its delegation methods.

But now, if I add it to the window of the AppDelegate class, it gives me the following error at runtime "ADBannerView must be part of the view hierarchy controlled by the UIViewController".

I think this means that I can use ADBanner only in the subclass file of the UIViewController ??

if so, how can I make it global?

Thanks at Advance Shreya

+5
source share
1 answer

In the AppDelegate class, you can create 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;
}

, iAds. , .

+6

All Articles