菜鸟教程小白 发表于 2022-12-12 13:15:18

iOS & Mopub : app freezes when loading ad on a slow network


                                            <p><p>我的代码如下所示,如入门指南中所述,请参阅链接:
<a href="http://help.mopub.com/customer/portal/articles/82831-start-guide" rel="noreferrer noopener nofollow">http://help.mopub.com/customer/portal/articles/82831-start-guide</a> </p>

<pre><code>- (void)viewDidLoad {
    self.adView = [   initWithAdUnitId:@&#34;xxx&#34; 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;
    ;
    ;
    ;
}
</code></pre>

<p>问题是当我启动应用程序时,它会启动 viewDidLoad 函数来加载广告。当网络非常慢或不存在时,广告的加载将卡住应用程序的执行约 20 秒。这是 Not Acceptable 行为。
有解决办法吗?</p></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>您可以尝试将 loadAd 方法链接到计时器或更好地使用基于 block 的可达性。
您可以从 <a href="https://github.com/tonymillion/Reachability" rel="noreferrer noopener nofollow">here</a> 获得可达性.</p>

<pre><code>// in view header file
NSTimer * aTimer;

//in implementation
-(void)viewDidLoad
{
    ...
    ;
    ;

    ;
   ...
}

-(void) loadAdIfReachable{
    // Allocate a reachability object
    Reachability* reach = ;

    // Set the blocks
    reach.reachableBlock = ^(Reachability*reach)
    {
      NSLog(@&#34;REACHABLE!&#34;);
      ;
      ;

    };
}
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于iOS &amp; Mopub : app freezes when loading ad on a slow network,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/18013603/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/18013603/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: iOS &amp; Mopub : app freezes when loading ad on a slow network