0

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.

Undo
  • 25,519
  • 37
  • 106
  • 129
Crashalot
  • 33,605
  • 61
  • 269
  • 439

1 Answers1

0

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.

Undo
  • 25,519
  • 37
  • 106
  • 129
  • thanks! quick question: isn't this inefficient since we're creating the banner every time there is an error (i.e., there is no ad for iAd to render)? thanks again. – Crashalot May 31 '13 at 19:15
  • also what do you mean by "remember to set the banners delegate to self" – Crashalot May 31 '13 at 19:16
  • @Crashalot **1.** It's just a bare-bones example. In the real world, you would probably keep a reference to the web view, and init it at startup, then add and remove it from the hierarchy as needed. – Undo May 31 '13 at 19:25
  • @Crashalot **2.** To receive the `didFailToReceiveAd` method, you need to be the banner view's delegate - set either in Interface Builder (just like a table view), or in code. – Undo May 31 '13 at 19:26
  • cool, thanks! so if we're modifying SAiOSAdPlugin.m (we will submit it a pull request to benefit the community), then we need to add code to the __prepare method that creates the web view? and then modify didFailToReceiveAdWithError to hide iAd while showing the webview? does setting webview.hidden = NO automatically show the web view? thanks again! – Crashalot May 31 '13 at 19:31
  • @Crash I don't know anything about the plugin in question, but that sounds about right. As always, try it! If it doesn't work, ask another question here (after Googling :). – Undo May 31 '13 at 19:34
  • ok, thanks! here's the plugin in case you're curious: https://github.com/shazron/iAdPlugin/blob/master/SAiOSAdPlugin.m. also, is setting webview.hidden = NO all that's necessary to show the webview? thanks! – Crashalot May 31 '13 at 19:59
  • @Crashalot Yes, **as long as it is in the subview tree**. Add it as a subview, then set hidden to YES/NO as you like. You could also use the `alpha`, which gives you finer grain control, and is animatable. – Undo May 31 '13 at 20:04
  • it's a little confusing as the github.com/shazron/iAdPlugin/blob/master/SAiOSAdPlugin.m code uses self.bannerIsVisible to show/hide the view. thanks anyway. we'll try to figure it out. – Crashalot May 31 '13 at 22:25
  • we tried using your code, but the UIWebView won't appear. we posted the question here if you could help: http://stackoverflow.com/questions/16867493/trouble-hiding-iad-banner-and-displaying-uiwebview-in-its-place. thanks again. – Crashalot Jun 01 '13 at 03:25
  • hey @undo, you there still? two more quick questions if you have time? – Crashalot Jun 01 '13 at 23:13
  • @Crashalot I'm going to be gone for a few hours - would tomorrow work? If they're quick, I can try to answer them fast right now, though. – Undo Jun 01 '13 at 23:20
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/31052/discussion-between-crashalot-and-undo) – Crashalot Jun 01 '13 at 23:22