Navigation Menu

Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.txt
Expand Up @@ -43,4 +43,4 @@ Once you have added the code library and additional frameworks to your project,
[AdBannerController sharedInstance].shouldDisplayAdMobAds = YES; [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.
4 changes: 2 additions & 2 deletions iAdPlusAdMob/AdBannerController.h
Expand Up @@ -2,13 +2,13 @@
// AdBannerController.h // AdBannerController.h
// //
// iAdPlusAdMob // iAdPlusAdMob
// Version 1.0.0 // Version 1.0.0
// //
// Created by PJ Cook on 22/03/2012. // Created by PJ Cook on 22/03/2012.
// Copyright (c) 2012 Software101. All rights reserved. // Copyright (c) 2012 Software101. All rights reserved.
// //
// Distributed under the permissive zlib License // 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 // https://github.com/pjcook/iAdPlusAdMob
// //
Expand Down
73 changes: 22 additions & 51 deletions iAdPlusAdMob/AdBannerController.m
Expand Up @@ -2,13 +2,13 @@
// AdBannerController.m // AdBannerController.m
// //
// iAdPlusAdMob // iAdPlusAdMob
// Version 1.0.0 // Version 1.0.0
// //
// Created by PJ Cook on 22/03/2012. // Created by PJ Cook on 22/03/2012.
// Copyright (c) 2012 Software101. All rights reserved. // Copyright (c) 2012 Software101. All rights reserved.
// //
// Distributed under the permissive zlib License // 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 // https://github.com/pjcook/iAdPlusAdMob
// //
Expand All @@ -34,11 +34,6 @@
#import "AdBannerController.h" #import "AdBannerController.h"


@interface AdBannerController() @interface AdBannerController()
{
id<AdBannerControllerDelegate> _delegate;
BOOL _shouldDisplayIAds;
BOOL _shouldDisplayAdMobAds;
}


@property (nonatomic, strong, readwrite) ADBannerView *bannerView; @property (nonatomic, strong, readwrite) ADBannerView *bannerView;
@property (nonatomic, strong, readwrite) GADBannerView *adMobBannerView; @property (nonatomic, strong, readwrite) GADBannerView *adMobBannerView;
Expand Down Expand Up @@ -108,49 +103,25 @@ + (void)removeSharedInstance
} }
} }


- (void)setShouldDisplayIAds:(BOOL)shouldDisplayIAds - (ADBannerView *)bannerView
{
_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
{ {
_shouldDisplayAdMobAds = shouldDisplayAdMobAds; if (bannerView == nil && _shouldDisplayIAds)

{
// create admob banner self.bannerView = [[ADBannerView alloc] init];
if (shouldDisplayAdMobAds && ![adMobId isEqualToString:@"NoAds"]) bannerView.delegate = self;
{ }
self.adMobBannerView = [[GADBannerView alloc] initWithFrame:[self adMobBannerSizeForDisplay]]; return bannerView;
self.adMobBannerView.delegate = self;
self.adMobBannerView.adUnitID = adMobId;
}
else
{
self.adMobBannerView.delegate = nil;
self.adMobBannerView = nil;
}
} }


- (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 - (CGRect)adMobBannerSizeForDisplay
Expand All @@ -162,15 +133,15 @@ - (CGRect)adMobBannerSizeForDisplay
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{ {
rect = CGRectMake(0.0f, mainWindow.bounds.size.height, rect = CGRectMake(0.0f, mainWindow.bounds.size.height,
GAD_SIZE_728x90.width, GAD_SIZE_728x90.width,
GAD_SIZE_728x90.height); GAD_SIZE_728x90.height);
} }
else else
{ {
rect = CGRectMake(0.0f, rect = CGRectMake(0.0f,
mainWindow.bounds.size.height, mainWindow.bounds.size.height,
GAD_SIZE_320x50.width, GAD_SIZE_320x50.width,
GAD_SIZE_320x50.height); GAD_SIZE_320x50.height);
} }
return rect; return rect;
} }
Expand Down