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

微笑、不失礼 提交于 2019-12-06 11:39:08

You may try linking loadAd method to a timer or better use block based reachability. You can get reachability from 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];

    };
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!