iOS 7将iAdAdditions类别带到UIViewController。 管理横幅是一行代码的问题:
self.canDisplayBannerAds = YES;
但我想知道如何检测用户触摸iAd横幅。我需要暂停游戏行为(音乐,动画,计时器......),而iAd全屏显示。
我尝试过以下代码:
- (void) viewWillDisappear:(BOOL)animated {
if ([self isPresentingFullScreenAd]) {
// view will disappear because of user action on iAd banner
}
else {
// view will disappear for any other reasons
}
}
- (void) viewWillAppear:(BOOL)animated {
if ([self isPresentingFullScreenAd]) {
// view will appear because full screen iAd — caused by previous user action on iAd banner — is dismissed
}
else {
// view will appear for other reasons
}
}
我做了一些测试,显示一切正常。但我想知道它是否是实施它的正确方法!
这是我在应用程序的生产版本中使用的解决方案,一切都很好:没有出现任何问题。
答案 0 :(得分:1)
您可以在视图控制器中使用这些特定代表,此处的代码直接从我的游戏中翻录,我点击横幅时切换音频/音乐。
- (BOOL)bannerViewActionShouldBegin:(ADBannerView *)banner
willLeaveApplication:(BOOL)willLeave
{
[[CPAudioManager sharedInstance] toggleOnOffDependingOnSettings];
return YES;
}
-(void)bannerViewActionDidFinish:(ADBannerView *)banner
{
[[CPAudioManager sharedInstance] toggleOnOffDependingOnSettings];
}
对于全屏插页式广告,代码大致相同,但您没有获得如此优秀的代表。
当您致电requestInterstitialAdPresentation
并返回YES
时,您知道何时展示全屏广告,例如
if( [self requestInterstitialAdPresentation]==YES ) {...}
你应该暂停你的观点,关闭你的音乐,并杀死你的横幅视图(可能)。
然后,您知道用户何时关闭ViewDidAppear
-(void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
if( self.isPresentingFullScreenAd )
{
// we are about to stop presenting full screen ads
// unpause view
// enable banner ads
// turn music back on if it was playing before
}
else
{
// we are presenting the normal view or the full screen ad
}
}