Skip to content

Commit

Permalink
added safe checks for defined ContentIdentifiers ( deprecated in 4.2 …
Browse files Browse the repository at this point in the history
…but new values not defined in 4.1 )

Stubbed orientation change handling - todo:
  • Loading branch information
Jesse committed Mar 15, 2011
1 parent 193a3cc commit cfd8544
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 16 deletions.
7 changes: 7 additions & 0 deletions AdPlugin/iOS/SAiOSAdPlugin.h
Expand Up @@ -17,13 +17,20 @@
BOOL bannerIsVisible;
BOOL bannerIsInitialized;
BOOL bannerIsAtBottom;

NSString* portraitContentIndentifier;
NSString* landscapeContentIndentifier;

}

@property (nonatomic, retain) ADBannerView* bannerView;
@property (assign) BOOL bannerIsVisible;
@property (assign) BOOL bannerIsInitialized;
@property (assign) BOOL bannerIsAtBottom;

@property (copy) NSString* portraitContentIndentifier;
@property (copy) NSString* landscapeContentIndentifier;


- (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
- (void) showAd:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
Expand Down
63 changes: 47 additions & 16 deletions AdPlugin/iOS/SAiOSAdPlugin.m
Expand Up @@ -19,13 +19,23 @@ - (void) __showAd:(BOOL)show;
@implementation SAiOSAdPlugin

@synthesize bannerView;
@synthesize bannerIsVisible, bannerIsInitialized, bannerIsAtBottom;
@synthesize bannerIsVisible;
@synthesize bannerIsInitialized;
@synthesize bannerIsAtBottom;
@synthesize portraitContentIndentifier;
@synthesize landscapeContentIndentifier;


#pragma mark -
#pragma mark Public Methods

- (void) prepare:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{

// [[NSNotificationCenter defaultCenter] addObserver:self
// selector:@selector(onOrientationChange)
// name:@"UIDeviceOrientationDidChangeNotification" object:nil];

NSUInteger argc = [arguments count];
if (argc > 1) {
return;
Expand All @@ -49,16 +59,39 @@ - (void) showAd:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)option
#pragma mark -
#pragma mark Private Methods

-(NSString*) getADBannerContentSizeIdentifierPortrait
{
if ( [ [ [ UIDevice currentDevice ] systemVersion ] floatValue ] >= 4.2 )
{
return ADBannerContentSizeIdentifierPortrait;
}

return ADBannerContentSizeIdentifier320x50;
}

-(NSString*) getADBannerContentSizeIdentifierLandscape
{
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 4.2)
{
return ADBannerContentSizeIdentifierLandscape;
}

return ADBannerContentSizeIdentifier480x32;
}

- (void) __prepare:(BOOL)atBottom
{
NSLog(@"SAiOSAdPlugin Prepare Ad At Bottom: %d", atBottom);

self.portraitContentIndentifier = [self getADBannerContentSizeIdentifierPortrait];
self.landscapeContentIndentifier = [self getADBannerContentSizeIdentifierLandscape];

Class adBannerViewClass = NSClassFromString(@"ADBannerView");
if (adBannerViewClass && !self.bannerView)
{
bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];

bannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: ADBannerContentSizeIdentifier320x50, ADBannerContentSizeIdentifier480x32, nil];
bannerView.requiredContentSizeIdentifiers = [NSSet setWithObjects: self.portraitContentIndentifier, self.landscapeContentIndentifier, nil];

bannerView.delegate = self;

Expand All @@ -72,11 +105,13 @@ - (void) __showAd:(BOOL)show
{
NSLog(@"SAiOSAdPlugin Show Ad: %d", show);

if (!self.bannerIsInitialized){
if (!self.bannerIsInitialized)
{
[self __prepare:NO];
}

if (!(NSClassFromString(@"ADBannerView") && self.bannerView)) { // ad classes not available
if (!(NSClassFromString(@"ADBannerView") && self.bannerView))
{ // ad classes not available
return;
}

Expand All @@ -100,12 +135,12 @@ - (void) __showAd:(BOOL)show
// First, setup the banner's content size and adjustment based on the current orientation
if(UIInterfaceOrientationIsLandscape(self.appViewController.interfaceOrientation))
{
bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
bannerView.currentContentSizeIdentifier = self.landscapeContentIndentifier;
bannerHeight = 32.0;
}
else
{
bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
bannerView.currentContentSizeIdentifier = self.portraitContentIndentifier;
}

bannerViewFrame.size.height = bannerHeight;
Expand Down Expand Up @@ -153,18 +188,14 @@ - (void) __showAd:(BOOL)show
}

[UIView commitAnimations];

}

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation))
self.bannerView.currentContentSizeIdentifier =
ADBannerContentSizeIdentifierLandscape;
else
self.bannerView.currentContentSizeIdentifier =
ADBannerContentSizeIdentifierPortrait;
}
//-(void)onOrientationChange
//{
// self.bannerIsVisible = !self.bannerIsVisible;
// [ self __showAd:(!self.bannerIsVisible)];
//
//}

#pragma mark -
#pragma ADBannerViewDelegate
Expand Down

0 comments on commit cfd8544

Please sign in to comment.