- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我目前正在代码中执行以下操作,以避免“模糊”广告的问题。但这是一个好的做法吗?一个潜在的问题是 - 假设在 viewWillDisappear 之前,发送了一个广告请求,然后当广告返回时,adBannerView 实例已经消失。这会是一个大问题吗?我应该只做 hideAdBanner 吗?
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear: animated];
// create the ad banner view
[self createAdBannerView];
if (adBannerView != nil) {
UIInterfaceOrientation orientation = self.interfaceOrientation;
[self changeBannerOrientation:orientation];
}
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
// iAd
if (adBannerView != nil) {
[self hideAdBanner];
adBannerView.delegate = nil;
[adBannerView release];
adBannerView = nil;
}
}
最佳答案
我对广告横幅使用单例,并在每个 ViewDidLoad 上将其调用到 View 中。这会自动将其从之前的 View 中删除。
这是针对 adWhirl 的,但您应该能够仅针对 iAD 采用它。
adWhirlSingleton.h
#import <Foundation/Foundation.h>
#import "AdWhirlDelegateProtocol.h"
#import "AdWhirlView.h"
@interface adWhirlSingleton : NSObject <AdWhirlDelegate> {
AdWhirlView *awView;
UIViewController *displayVC;
}
@property (strong, nonatomic) AdWhirlView *awView;
@property (strong, nonatomic) UIViewController *displayVC;
+(id)sharedAdSingleton;
-(void)adjustAdSize:(CGFloat)x:(CGFloat)y;
@end
adWhirlSingleton.m
#import "adWhirlSingleton.h"
@implementation adWhirlSingleton
static adWhirlSingleton* _sharedAdSingleton = nil;
@synthesize awView, displayVC;
+(id)sharedAdSingleton
{
@synchronized(self)
{
if(!_sharedAdSingleton)
_sharedAdSingleton = [[self alloc] init];
return _sharedAdSingleton;
}
return nil;
}
+(id)alloc
{
@synchronized([adWhirlSingleton class])
{
NSAssert(_sharedAdSingleton == nil, @"Attempted to allocate a second instance of a singleton.");
_sharedAdSingleton = [super alloc];
return _sharedAdSingleton;
}
return nil;
}
-(id)init
{
self = [super init];
if (self != nil) {
// initialize stuff here
self.awView = [AdWhirlView requestAdWhirlViewWithDelegate:self];
}
return self;
}
-(void)dealloc
{
displayVC = nil;
if (awView) {
[awView removeFromSuperview]; //Remove ad view from superview
[awView replaceBannerViewWith:nil];
[awView ignoreNewAdRequests]; // Tell adwhirl to stop requesting ads
[awView setDelegate:nil];
awView = nil;
}
}
-(void)adjustAdSize:(CGFloat)x :(CGFloat)y
{
[UIView beginAnimations:@"AdResize" context:nil];
[UIView setAnimationDuration:0.7];
awView.frame = CGRectMake(x, y, kAdWhirlViewWidth, kAdWhirlViewHeight);
[UIView commitAnimations];
NSLog(@"Recent Network Name: %@",[awView mostRecentNetworkName]);
}
-(BOOL)adWhirlTestMode
{
return YES;
}
-(NSString *)adWhirlApplicationKey
{
return @"xxxxxxxxxxxxx";
}
-(UIViewController *)viewControllerForPresentingModalView
{
return displayVC;
}
-(void)adWhirlDidReceiveAd:(AdWhirlView *)adWhirlView
{
NSLog(@"%s",__FUNCTION__);
NSLog(@"Recent Network Name: %@",[awView mostRecentNetworkName]);
//[self adjustAdSize];
}
-(void)adWhirlDidFailToReceiveAd:(AdWhirlView *)adWhirlView usingBackup:(BOOL)yesOrNo
{
NSLog(@"%s",__FUNCTION__);
}
@end
然后将 adWhirlSingleton 导入到每个 ViewController 中,并且在每个 viewWillAppear 中我只需实现此:
adWhirlSingleton *adWhirlSingle = [adWhirlSingleton sharedAdSingleton];
adWhirlSingle.displayVC = self;
[adWhirlSingle adjustAdSize:0 :self.view.frame.size.height -50];
[self.view addSubview:adWhirlSingle.awView];
[self.view bringSubviewToFront:adWhirlSingle.awView];
NSLog(@"Ad Banner View");
但是我使用 UITableView 的 View ,我使用这个:
adWhirlSingleton *adWhirlSingle = [adWhirlSingleton sharedAdSingleton];
adWhirlSingle.displayVC = self;
[adWhirlSingle adjustAdSize:0 :self.tabBarController.view.frame.size.height -99];
[self.tabBarController.view addSubview:adWhirlSingle.awView];
NSLog(@"Should have added Ad!");
希望对你有一点帮助
关于iphone - 删除 viewWillDisappear 上的 AdBannerView 并将其添加回 viewWillAppear 是一个好习惯吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9422177/
我尝试用像 Objective C 这样的旧方法来实现 ADBannerView 但没有成功。一切正常,但广告没有出现,它仍然是一个空白字段。 func bannerViewDidLoadAd(ban
我的所有 viewcontroller 页面上都有此代码,用于跨多个页面控制我的 AdBanner。它在我的应用程序的最新版本上正常工作,但由于某种原因,在此更新中我正在处理我认为我的应用程序没有调用
我正在使用 AdBannerView,并且在调试我的应用程序时在“应用程序输出”窗口中看到以下消息。 ADBannerView: WARNING A banner view (0x98c0c40) h
我正在为 iPhone 开发一个需要支持 iAds 的应用程序。该应用程序有一个包含 html 内容的主视图,当加载 iAd 时,它必须调整主视图的大小,以便广告显示在底部。一切都很好并且工作正常,除
广告会自行消失吗?我读到广告应该在关闭前显示 30 秒,这意味着它们的显示由应用程序管理,但在预发布测试中,它们会在 30 秒后自行消失。 此外,如果我为无广告升级提供应用内购买,防止加载广告的最佳方
我的应用程序已获得批准,现在它在 App Store 上运行正常,并且在模拟器中广告横幅按预期工作,但问题是在我发布的应用程序中没有广告,所以我首先要坚持肯定是下载量的问题,但是我一直在网上找,我发现
我的应用程序中有一些奇怪的东西,因为我是 ADBannerView 的初学者,我希望有人能帮助我。 我已经在 appDelegate.swift 中配置了创建和管理 ADBannerView 的方法,
我正在尝试将 iAd Banner 放入我的游戏中!我已经在游戏中担任主角很长一段时间,等待正常的 Apple iAd 广告出现,但它没有出现。它根本没有出现在我的屏幕上! 我做错了什么吗? 还是最终
使用标准的 UINavigationController 根应用程序是否可以在屏幕底部、 View 层次结构下方显示单个 ADBannerView?也就是说,在不修改每个可以推送到根 UINaviga
当用户更改屏幕时,我想隐藏当前的 ADBannerView 。有没有“正确”的方法来做到这一点?例如,如果我将其移出屏幕,可以吗:我想知道它是否可以在不显示的情况下继续转换广告,然后我会违反一些苹果协
我正在维护 ADBannerView 的唯一实例(如文档所建议的),并且在整个 UX 中的某些点存在。 但我可以看到 bannerViewDidLoadAd:即使未显示横幅,回调也会继续被调用。 一方
如果您添加一个 ADBannerView,您可以检测它何时从其委托(delegate)函数加载广告: - (void)bannerViewDidLoadAd:(ADBannerView *)banne
我的应用程序上有一个广告,在您点击它之前,它会加载标准测试广告屏幕,但最近当我这样做时它会返回此错误: *** Assertion failure in NSDictionary *_UIRecord
我关注了这个tutorial ,但我的例子比上面提到的稍微复杂一些。我的示例底部有一个 TabBar ,上面有一个 UITableViewController 。在此 UITableViewContr
在我支持所有设备方向的 iPad 应用程序中,我将 adBannerView 添加到主视图。 到目前为止一切顺利。它有效并且广告按预期轮播。 如果我点击一个特定的广告,它会全屏显示,当我关闭它时,我会
我正在以编程方式在我的 iPhone 应用程序中创建 ADBannerView, 有人能这么说吗 为什么我在控制台中收到此消息, ADBannerView: Unhandled error (no d
我想将 iAd 横幅集成到 UItableViewController 中的 tableView 下方。目标是调整 tableview 的大小并添加到 UIViewController 的底部,在本例
我正在尝试在我的应用程序底部插入一个 iad 横幅,但在按照教程进行操作后不断出现错误。代码如下。 @interface DMKHomeViewController (UIViewcontroller
我按照苹果开发指南文档以编程方式在我的 iOS 应用程序上添加 iAd。虽然我在 stackoverflow 上搜索了以前的解决方案,但不幸的是它们似乎都没有帮助我。这是以下错误: iAdBanner
我在设备上得到一个着色的 adBannerView,而不是模拟器中显示的普通 adBannerView。对此有什么想法吗? 最佳答案 在设备上,转到“设置”>“开发人员”并禁用“突出显示剪裁横幅”选项
我是一名优秀的程序员,十分优秀!