I am having trouble with an iOS 8 app. My app needs to get information from a web server to determine if ads should be played or not. This can take a while, so the code in viewDidLoad
doesn't wait for it and instead calls setCanDisplayBannerAds:NO
. Then later, once the information comes in, setCanDisplayBannerAds:YES
is called outside of viewDidLoad
.
I have determined that I need to call setCanDisplayBannerAds:NO
inside viewDidLoad
otherwise setCanDisplayBannerAds:YES
doesn't properly invoke the ads and generates lots of internal exceptions.
The issue is that once ads are enabled outside of viewdidLoad
, the layout messes up. I've illustrated with two images below. The top one is "before", the bottom "after", as in after Show Ads is tapped.
Note in the "before" image that Show Ads and Just a Label both appear in their respective corners after rotation. In the "after" image, the landscape orientation is no longer correct. It maintains the portrait bounds with Just a Label and the banner ad cut off.
I have submitted a bug report to Apple and provided a sample project accessible on DropBox as ID19658866.zip. Feel free to download it and try it out.
If anyone can provide some insight, and maybe a solution where I don't have to change the logical sequence, i.e. not showing ads until after viewDidLoad
is completed, that would be much appreciated.
Put these two lines in viewdidLoad:
[self setCanDisplayBannerAds:YES];
[self setCanDisplayBannerAds:NO];
The first call sets up the ads correctly, the second right away makes sure they don't show. Later you can call [self setCanDisplayBannerAds:YES];
and it will handle orientation changes without problem.