我的代码如下所示,如入门指南中所述,请参阅链接:
http://help.mopub.com/customer/portal/articles/82831-start-guide
- (void)viewDidLoad {
self.adView = [[MPAdView alloc] initWithAdUnitId"xxx" size:MOPUB_BANNER_SIZE];
self.adView.delegate = self;
self.adView.frame = CGRectMake(0, self.view.bounds.size.height - MOPUB_BANNER_SIZE.height, MOPUB_BANNER_SIZE.width, MOPUB_BANNER_SIZE.height);
self.adView.keywords = keywords;
[self.view addSubview:self.adView];
[self.adView loadAd];
[super viewDidLoad];
}
问题是当我启动应用程序时,它会启动 viewDidLoad 函数来加载广告。当网络非常慢或不存在时,广告的加载将卡住应用程序的执行约 20 秒。这是 Not Acceptable 行为。
有解决办法吗?
Best Answer-推荐答案 strong>
您可以尝试将 loadAd 方法链接到计时器或更好地使用基于 block 的可达性。
您可以从 here 获得可达性.
// in view header file
NSTimer * aTimer;
//in implementation
-(void)viewDidLoad
{
...
[self.view addSubview:self.adView];
[self.adview setHidden:YES];
[self loadAdIfReachable];
...
}
-(void) loadAdIfReachable{
// Allocate a reachability object
Reachability* reach = [Reachability reachabilityWithHostname"www.google.com"];
// Set the blocks
reach.reachableBlock = ^(Reachability*reach)
{
NSLog(@"REACHABLE!");
[self.adview setHidden:NO];
[self.adView loadAd];
};
}
关于iOS & Mopub : app freezes when loading ad on a slow network,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/18013603/
|