iAd & Admob Interstitial Integration on iPhone

白昼怎懂夜的黑 提交于 2019-12-06 03:45:37

问题


I'm currently using Admob GADInterstitial in my iPhone app, and would like to take advantage of the interstitials offered in the iAd UIViewController additions in iOS 7.

My guess is that Apple's fill rate will not be that high, so I'd like to fall back to Admob if an ad isn't available. Unfortunately the API for iAd looks really opaque, and I don't see a way to determine if an ad is available.

Has anyone successfully done this, and if so, how?


回答1:


I missed that the manual presentation approach, calling requestInterstitialAdPresentation, returns a BOOL that says whether an ad will be displayed. Theoretically, I can use this to control whether to fall back to admob. I'll post a comment later on whether it worked or not.

EDIT: It works!

It turns out requestInterstitialAdPresentation does appropriately answer true or false. Then the only thing that remains to make it feel like the other APIs is to figure out when the ad VC is dismissed. I did this by responding in the viewDidAppear: method of the hosting view controller if an ad had been launched. I actually have it encapsulated in an AdManager class,and use an NSNotification to communicate the viewDidAppear:, so was able to drop in iAds pretty cleanly.




回答2:


You can check following library which will seamlessly integrate iAd and Google Ads.

https://github.com/larsacus/LARSAdController

I have been using it for fews months and it is cool.




回答3:


To control iAd in your view controller you can setup a delegate to listen for iAd states:

@interface MyViewController : UIViewController <ADBannerViewDelegate>
...

@property (nonatomic, weak) IBOutlet ADBannerView* banner;

@end

then in your implementation file:

@implementation MyViewController

- (void)viewDidLoad
{
   ...
   [_banner setHidden:YES];
   _banner.delegate = self;
} 

...

#pragma mark - ADBannerViewDelegate implementation

- (void)bannerView:(ADBannerView*)banner didFailToReceiveAdWithError:(NSError*)error
{
    // iAd is not available, so we are going to hide it to get rid of ugly white rectangle
    [_banner setHidden:YES];
    // Here you can add your logic to show your other ads
}

- (void)bannerViewDidLoadAd:(ADBannerView*)banner
{
    // iAd is available, lets show it
    [_banner setHidden:NO];
    // Here you can add your logic to hide your other ads
}

@end

Also I normally keep just one instance of ADBannerView, have it in my App Delegate and once some view controller appears on a screen - I simply add that ADBannerView to view hierarchy of view controller and remove it when view controller disappears.



来源:https://stackoverflow.com/questions/19102935/iad-admob-interstitial-integration-on-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!