简体   繁体   English

iPhone上的iAd和Admob插页式整合

[英]iAd & Admob Interstitial Integration on iPhone

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. 我目前正在我的iPhone应用程序中使用Admob GADInterstitial,并希望利用iOS 7中iAd UIViewController附加功能中提供的插页式广告。

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. 我的猜测是Apple的填充率不会那么高,所以如果广告不可用,我想回到Admob。 Unfortunately the API for iAd looks really opaque, and I don't see a way to determine if an ad is available. 不幸的是,iAd的API看起来非常不透明,我看不到确定广告是否可用的方法。

Has anyone successfully done this, and if so, how? 有没有人成功地做到了这一点,如果有的话,怎么样?

I missed that the manual presentation approach, calling requestInterstitialAdPresentation , returns a BOOL that says whether an ad will be displayed. 我错过了手动演示方法,调用requestInterstitialAdPresentation ,返回一个BOOL,说明是否会显示广告。 Theoretically, I can use this to control whether to fall back to admob. 从理论上讲,我可以用它来控制是否回归到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. 事实证明,requestInterstitialAdPresentation适当地回答了真或假。 Then the only thing that remains to make it feel like the other APIs is to figure out when the ad VC is dismissed. 然后唯一让它感觉像其他API一样的东西是弄清楚广告VC什么时候被解雇。 I did this by responding in the viewDidAppear: method of the hosting view controller if an ad had been launched. 如果广告已经启动,我通过在托管视图控制器的viewDidAppear:方法中做出响应来做到这一点。 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. 我实际上将它封装在AdManager类中,并使用NSNotification来传递viewDidAppear:,因此能够非常干净地放入iAds。

You can check following library which will seamlessly integrate iAd and Google Ads. 您可以查看以下库,它将无缝集成iAd和Google广告。

https://github.com/larsacus/LARSAdController https://github.com/larsacus/LARSAdController

I have been using it for fews months and it is cool. 我已经使用了几个月,很酷。

To control iAd in your view controller you can setup a delegate to listen for iAd states: 要在视图控制器中控制iAd,您可以设置一个委托来监听iAd状态:

@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. 此外,我通常只保留一个ADBannerView实例,将它放在我的App Delegate中,一旦某个视图控制器出现在屏幕上 - 我只需添加ADBannerView即可查看视图控制器的层次结构,并在视图控制器消失时将其删除。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM