Search code examples
iosobjective-cios5cordova

How to show or hide small view containing web page in iOS app based on certain conditions?


We're building an iPhone app and using this iAd plugin from PhoneGap: https://github.com/shazron/iAdPlugin/blob/master/SAiOSAdPlugin.m.

Because we built the app with HTML5, not Objective-C, and don't know how to adjust the plug-in.

When iAd lacks inventory, it displays a blank, white rectangle (320x50). We would like to display a 320x50 web page instead of the white rectangle, acting as a fallback ad, only show iAd when it has ad inventory again.

We know it's necessary to include code in (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError*)error, but would love tips on what to do next.


Solution

  • Just use this:

    - (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError*)error
    {
        banner.hidden = YES;
        UIWebView *webview = ... //Make it.
        webview.frame = banner.frame;
        [self.view addSubview:webview];
    }
    

    Unless I'm missing something huge, this should work - remember to set the banners delegate to self, though.