Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Changed bannerView to a lazy getter to avoid crash when AdBannerController is initialised before window has loaded #1

Merged
merged 1 commit into from Apr 2, 2012
Jump to file or symbol
Failed to load files and symbols.
+25 −54
Split
View
@@ -43,4 +43,4 @@ Once you have added the code library and additional frameworks to your project,
[AdBannerController sharedInstance].shouldDisplayAdMobAds = YES;
}
-The static initialize method is only called only during the application life cycle and is therefore the best place to singularly initialize any of your components and libraries.
+The static initialize method is only called once during the application life cycle and is therefore the best place to singularly initialize any of your components and libraries.
@@ -2,13 +2,13 @@
// AdBannerController.h
//
// iAdPlusAdMob
-// Version 1.0.0
+// Version 1.0.0
//
// Created by PJ Cook on 22/03/2012.
// Copyright (c) 2012 Software101. All rights reserved.
//
// Distributed under the permissive zlib License
-// Get the latest version from either of this location:
+// Get the latest version from here:
//
// https://github.com/pjcook/iAdPlusAdMob
//
@@ -2,13 +2,13 @@
// AdBannerController.m
//
// iAdPlusAdMob
-// Version 1.0.0
+// Version 1.0.0
//
// Created by PJ Cook on 22/03/2012.
// Copyright (c) 2012 Software101. All rights reserved.
//
// Distributed under the permissive zlib License
-// Get the latest version from either of this location:
+// Get the latest version from here:
//
// https://github.com/pjcook/iAdPlusAdMob
//
@@ -34,11 +34,6 @@
#import "AdBannerController.h"
@interface AdBannerController()
-{
- id<AdBannerControllerDelegate> _delegate;
- BOOL _shouldDisplayIAds;
- BOOL _shouldDisplayAdMobAds;
-}
@property (nonatomic, strong, readwrite) ADBannerView *bannerView;
@property (nonatomic, strong, readwrite) GADBannerView *adMobBannerView;
@@ -108,49 +103,25 @@ + (void)removeSharedInstance
}
}
-- (void)setShouldDisplayIAds:(BOOL)shouldDisplayIAds
-{
- _shouldDisplayIAds = shouldDisplayIAds;
-
- // create iAd banner
- if (shouldDisplayIAds)
- {
- self.bannerView = [[ADBannerView alloc] init];
- self.bannerView.delegate = self;
- }
- else
- {
- self.bannerView.delegate = nil;
- self.bannerView = nil;
- }
-}
-
-- (BOOL)shouldDisplayIAds
-{
- return _shouldDisplayIAds;
-}
-
-- (void)setShouldDisplayAdMobAds:(BOOL)shouldDisplayAdMobAds
+- (ADBannerView *)bannerView
{
- _shouldDisplayAdMobAds = shouldDisplayAdMobAds;
-
- // create admob banner
- if (shouldDisplayAdMobAds && ![adMobId isEqualToString:@"NoAds"])
- {
- self.adMobBannerView = [[GADBannerView alloc] initWithFrame:[self adMobBannerSizeForDisplay]];
- self.adMobBannerView.delegate = self;
- self.adMobBannerView.adUnitID = adMobId;
- }
- else
- {
- self.adMobBannerView.delegate = nil;
- self.adMobBannerView = nil;
- }
+ if (bannerView == nil && _shouldDisplayIAds)
+ {
+ self.bannerView = [[ADBannerView alloc] init];
+ bannerView.delegate = self;
+ }
+ return bannerView;
}
-- (BOOL)shouldDisplayAdMobAds
+- (GADBannerView *)adMobBannerView
{
- return _shouldDisplayAdMobAds;
+ if (adMobBannerView == nil && _shouldDisplayAdMobAds && ![adMobId isEqualToString:@"NoAds"])
+ {
+ self.adMobBannerView = [[GADBannerView alloc] initWithFrame:[self adMobBannerSizeForDisplay]];
+ adMobBannerView.delegate = self;
+ adMobBannerView.adUnitID = adMobId;
+ }
+ return adMobBannerView;
}
- (CGRect)adMobBannerSizeForDisplay
@@ -162,15 +133,15 @@ - (CGRect)adMobBannerSizeForDisplay
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
rect = CGRectMake(0.0f, mainWindow.bounds.size.height,
- GAD_SIZE_728x90.width,
- GAD_SIZE_728x90.height);
+ GAD_SIZE_728x90.width,
+ GAD_SIZE_728x90.height);
}
else
{
rect = CGRectMake(0.0f,
- mainWindow.bounds.size.height,
- GAD_SIZE_320x50.width,
- GAD_SIZE_320x50.height);
+ mainWindow.bounds.size.height,
+ GAD_SIZE_320x50.width,
+ GAD_SIZE_320x50.height);
}
return rect;
}