So I have added iAds to my application and I have done this very simply. By importing iAds into the ViewController.h and putting the following code into the ViewController.m file:
self.canDisplayBannerAds = YES;
This works, however, when I the add loads the screen is squished. Where all of the images and sprites become shorter.
Is there any way the add can just be overlaid on top of the SKScene? so that is does not affect the elements below – so that it stops the squishing?
Also, is there a way to only have the banner ads run in certain SKScenes or when a BOOL is changed from YES to NO?
UPDATED
Code from my project:
#import "XYZViewController.h"
#import "XYZMenuScene.h"
#import <iAd/iAd.h>
#implementation XYZViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
// Create and configure the scene.
SKScene * scene = [XYZMenuScene sceneWithSize:skView.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
//iAds Enabled
self.canDisplayBannerAds = YES;
// Present the scene.
[skView presentScene:scene];
}
This is all I have in terms of the iAds. It makes the entire scene push upwards to make room for the ad banner. Where I want it to just be over the scene and not push anything. So it covers, instead of pushes.
To overlay you can set the Z position of the banner higher than the rest of the content by default it's 0.
eg:
banner.layer.zPosition=2;
but I believe the iAd framework has built in method thats you can override to control when the ads must display and when they shouldn't and give you much more control.
Specific methods are called when the ad is available,and like you said you make the ads appear only when a boolean value is 1 or 0.
eg:
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
if(showADS==1)
{
if (!self.bannerIsVisible)
{
[UIView beginAnimations:#"animateAdBannerOn" context:NULL];
// Assumes the banner view is just off the bottom of the screen.
banner.frame = CGRectOffset(banner.frame, 0, -banner.frame.size.height);
[UIView commitAnimations];
self.bannerIsVisible = YES;
}
}
else
{NSlog(#"No ads");}
}
check apple's documentation regarding this,they are really helpful
https://developer.apple.com/library/ios/documentation/userexperience/Conceptual/iAd_Guide/WorkingwithBannerViews/WorkingwithBannerViews.html
But let give a complete example.
The banner instance is only available in you iAd Methods not outside them.
In your view did load method:
- (void)viewDidLoad
{
self.canDisplayBannerAds=YES;
}
This method is called when the ad is loaded,in this method specify the position of the ad
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
banner.layer.zPosition=2;
/*do all the additional like checking is the boolean is 1 or 0 etc.*/
}
If you are working with iAd and sprite kit,you need to call methods in your view controller from the scene class to do all the ad work.
Suppose you have a method named checkAD in your view controller that checks if the ad should shown or not etc..
You can call this method from your scene class by using this code
if([self.delegate respondsToSelector:#selector(checkAD)]){
[self.delegate checkAD];
}
Add the SKSCene in a container View that might help. From my experience any Apple subclasses of UIViewController can do weird stuff when iAds are added through canDisplayBannerAds.
Related
I'm working with the Google Mobile Ads SDK on iOS and trying to display some ads. My code:
GADBannerView* bannerView = [[GADBannerView alloc] initWithAdSize:GADAdSizeFromCGSize(CGSizeMake(300, 250))];
bannerView.adUnitID = #"hidden";
bannerView.rootViewController = self;
bannerView.delegate = self;
GADRequest* request = [GADRequest request];
request.testDevices = #[ kGADSimulatorID ];
[bannerView loadRequest:request];
This works fine if I add the bannerView to the view hierarchy right after the code you see above. However, I don't really want to add it until the ad is loaded, so I wanted to delay it. I noticed that if the bannerView is not in the view hierarchy, the delegate methods are not called at all. Furthermore, I have found this answer, which is in line with what I'm observing. On the other hand, this is a quote from the GADBannerViewDelegate header:
/// Tells the delegate that an ad request successfully received an ad. The delegate may want to add
/// the banner view to the view hierarchy if it hasn't been added yet.
- (void)adViewDidReceiveAd:(GADBannerView *)bannerView;
This suggests that it should be possible to receive those delegate callbacks even if the view is not in the hierarchy, which is exactly what I want. So, any ideas how could I achieve this?
Ok, so the problem here was that I didn't keep the reference to the bannerView. It was deallocated after the method returned, and this is why the delegate methods were not called.
I just had the same issue after upgrading from the Admob SDK 7.56 to 8.2:
They changed the method names of the GADBannerViewDelegate protocol.
E.g. instead of
-(void)adViewDidReceiveAd:(GADBannerView *)adView;
it is now
-(void)bannerViewDidReceiveAd:(GADBannerView *)bannerView;
see also the migration guide to Admob SDK version 8:
https://developers.google.com/admob/ios/migration#methods_removedreplaced
You should add the GADBannerView to your view and set its hidden property to YES initially. Also, I'd suggest using the AdSize Constant kGADAdSizeBanner that AdMob provides. Here's a list of additional AdSize Constants.
For example:
bannerView = [[GADBannerView alloc] initWithAdSize:kGADAdSizeBanner];
bannerView.adUnitID = #"YourAdUnitID";
bannerView.rootViewController = self;
bannerView.delegate = self;
[bannerView loadRequest:[GADRequest request]];
bannerView.hidden = YES; // Hide banner initially
[self.view addSubview:bannerView];
// This will put the banner at the bottom of the screen and stretch to fit the screens width
[bannerView setFrame:CGRectMake(0, self.view.frame.size.height - bannerView.frame.size.height, self.view.frame.size.width, bannerView.frame.size.height)];
Then, when you receive an ad you unhide the banner. For example:
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
// We've received an ad so lets show the banner
bannerView.hidden = NO;
NSLog(#"adViewDidReceiveAd");
}
-(void)adView:(GADBannerView *)adView didFailToReceiveAdWithError:(GADRequestError *)error {
// Failed to receive an ad from AdMob so lets hide the banner
bannerView.hidden = YES;
NSLog(#"adView:didFailToReceiveAdWithError: %#", [error localizedDescription]);
}
You could also animate this, if you'd prefer, by setting the banner's alpha property to 0.0 initially instead of using it's hidden property. Then, animate the alpha when you receive an ad. For example:
-(void)adViewDidReceiveAd:(GADBannerView *)adView {
// We've received an ad so lets fade in the banner
[UIView animateWithDuration:0.2 animations:^{
bannerView.alpha = 1.0;
}];
NSLog(#"adViewDidReceiveAd");
}
-(void)adView:(GADBannerView *)adView didFailToReceiveAdWithError:(GADRequestError *)error {
// Failed to receive an ad from AdMob so lets fade out the banner
[UIView animateWithDuration:0.2 animations:^{
bannerView.alpha = 0.0;
}];
NSLog(#"adView:didFailToReceiveAdWithError: %#", [error localizedDescription]);
}
Also, as a side note, the GADBannerView is transparent when there is no ad to display. So, adding it to your view and doing nothing else would work too.
Since xCode was updated to version 6.0, the default method for SpriteKit in "GameScene" (the default scene created) changes to:
-(void) didMoveToView:(SKView *) view {
/* Scene set up in here */
}
as opposed to the older method:
-(id) initWithSize:(CGSize) size {
if (self = [super initWithSize:size]{
/* Scene set up in here */
}
}
I understand that the new method (as with the changes in the view controller) is used to help manage the import from the .sks file that is new in xCode 6. However, I was curious if I didn't want to use the new "storyboard"-type format that is the .sks file, should I still use the new method? Or should I change the method back to the initWithSize method and just delete the .sks file?
Init methods should be used for initializing but keep in mind that inside init, view is always nil. So any code that needs the view has to be moved to didMoveToView method (it's called immediately after a scene is presented by a view).
About initWithSize in Xcode 6... By default, scene is loaded from .sks file. Because of this, initWithSize is never called actually. initWithCoder is called instead:
- (instancetype)initWithCoder:(NSCoder *)aDecoder
{
if (self = [super initWithCoder:aDecoder]) {
// do stuff
}
return self;
}
So initializing anything inside initWithSize won't have any effect. If you decide to delete .sks file and create a scene in "old" way, you can do something like this in view controller:
- (void)viewDidLoad
{
[super viewDidLoad];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;
// Create and configure the scene.
GameScene *scene = [GameScene sceneWithSize:self.view.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
After that, you can use initWithSize for initialization.
Note that in viewDidLoad the final size of a view may not be known yet, and using viewWillLayoutSubviews instead could be a right choice. Read more here.
And proper implementation of viewWillLayoutSubviews for scene initialization purpose would be:
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
// Configure the view.
SKView * skView = (SKView *)self.view;
skView.showsFPS = YES;
skView.showsNodeCount = YES;
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = YES;
//viewWillLayoutSubviews can be called multiple times (read about this in docs ) so we have to check if the scene is already created
if(!skView.scene){
// Create and configure the scene.
GameScene *scene = [GameScene sceneWithSize:self.view.bounds.size];
scene.scaleMode = SKSceneScaleModeAspectFill;
// Present the scene.
[skView presentScene:scene];
}
}
Swift code:
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
if let scene = GameScene.unarchiveFromFile("GameScene") as? GameScene {
// Configure the view.
let skView = self.view as SKView
skView.showsFPS = true
skView.showsNodeCount = true
skView.showsPhysics = true
skView.showsDrawCount = true
/* Sprite Kit applies additional optimizations to improve rendering performance */
skView.ignoresSiblingOrder = true
/* Set the scale mode to scale to fit the window */
if(skView.scene == nil){
scene.scaleMode = .AspectFill
scene.size = skView.bounds.size
skView.presentScene(scene)
}
}
}
I think that, for all intents and purposes, there isn't much of a difference between the two methods when it comes to actually setting up your scene and using it. (initWithSize is called when the scene is initialized, while didMoveToView is always called right when the scene is presented by the view). I guess if you really prefer to see the initialization then you could just use the init method without any trouble at all.
Regarding the .sks file:
take a look at your view controller implementation file. Right above the v.controller's methods you'll see:
#implementation SKScene (Unarchive)
+ (instancetype)unarchiveFromFile:(NSString *)file {
/* Retrieve scene file path from the application bundle */
NSString *nodePath = [[NSBundle mainBundle] pathForResource:fileofType:#"sks"];
/* Unarchive the file to an SKScene object */
NSData *data = [NSData dataWithContentsOfFile:nodePath
options:NSDataReadingMappedIfSafe
error:nil];
NSKeyedUnarchiver *arch = [[NSKeyedUnarchiver alloc] initForReadingWithData:data];
[arch setClass:self forClassName:#"SKScene"];
SKScene *scene = [arch decodeObjectForKey:NSKeyedArchiveRootObjectKey];
[arch finishDecoding];
return scene;
}
#end
This is the part that handles the sks. Using the file is totally optional, you aren't forced to do it and it really has no impact on you setting up your scene. However, if you do want to work with it, then you'll find that you'll need to work with this code snippet.
Both options are correct. Said that, the init method is not actually the same than the didMoveToView: method, as this last one will be called once the SKScene is presented in a SKView.
When my app was in development, iAds worked great. Every 30 seconds I would either get a call to "bannerViewDidLoadAd" or to "didFailToReceiveAdWithError" and I prepared the app to handle either callback. I get the green checkmark "You're connected to iAd's App Network" and the other test ads.
Now that the app is live, it only gets "didFailToReceiveAdWithError" and never loads an ad.
I'm running the released version of the app on my phone plugged in to the Xcode Organizer Console, and I see the NSLog that prints within "didFailToReceiveAdWithError"
The iAd Portal doesn't show any requests though, it lists 0 requests.
I've built it to my phone again from XCode with the development profile and again it works as it should. I've deleted the app, shut down my phone, signed out of my iTunes Apple ID, and redownloaded the app from the App Store and still the ad fails every time.
Here's how I've got the ad coded:
In my rootViewController, the user chooses to start a new game, and I animate the new view:
UIViewController *nextController = [[GamePlayViewController alloc] initWithNibName:#"GamePlayView" bundle:nil];
[nextController performSelector:#selector(setDelegate:) withObject:self];
nextController.view.frame = CGRectMake(0, 570, 320, 568);
[self.view addSubview:nextController.view];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationDuration:0.23];
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:#selector(animationDidStop:finished:context:)];
nextController.view.frame = CGRectMake(0, 0, 320, 568);
[UIView commitAnimations];
temporaryController = nextController;
GamePlayViewController.h includes:
- #import <iAd/iAd.h>
- #interface GamePlayViewController : UIViewController <ADBannerViewDelegate, UIDocumentInteractionControllerDelegate> {
GamePlayViewController.m includes:
- ADBannerView *_bannerView;
Once the user is in GamePlayViewController.m, there is an animation triggered in viewDidLoad, and once that animation completes, an ad is called:
if ([ADBannerView instancesRespondToSelector:#selector(initWithAdType:)]) {
_bannerView = [[ADBannerView alloc] initWithAdType:ADAdTypeBanner];
} else {
_bannerView = [[ADBannerView alloc] init];
}
_bannerView.delegate = self;
[self.view bringSubviewToFront:_bannerView];
}
That's really all there is to it other than the callback methods for iAds.
- (void)bannerViewDidLoadAd:(ADBannerView *)banner
{
NSLog(#"ad loaded!");
_bannerView.hidden = NO;
[self layoutAnimated:YES];
}
- (void)layoutAnimated:(BOOL)animated
{
// As of iOS 6.0, the banner will automatically resize itself based on its width.
// To support iOS 5.0 however, we continue to set the currentContentSizeIdentifier appropriately.
CGRect contentFrame = self.view.bounds;
if (contentFrame.size.width < contentFrame.size.height) {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
} else {
_bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
}
CGRect bannerFrame = _bannerView.frame;
if (_bannerView.bannerLoaded) {
bannerFrame.origin.y = 0;
} else {
bannerFrame.origin.y = contentFrame.size.height;
}
[UIView animateWithDuration:animated ? 0.25 : 0.0 animations:^{
_contentView.frame = contentFrame;
[_contentView layoutIfNeeded];
_bannerView.frame = bannerFrame;
[self.view addSubview:_bannerView];
}];
}
- (void)bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error
{
NSLog(#"ad failed!");
_bannerView.hidden = YES;
}
Maybe something I am doing is wrong or I should have the ad on the rootViewController itself, but this code works great with test iAds, so I'm not sure why it's not working with the App Store version of the app.
Thanks for any help!
I've not looked at your code but I've observed this also. Sometimes Apple just hasn't sold any ads so there aren't any to display for you. Consider using an ad aggregator. I use https://github.com/larsacus/LARSAdController but modified it to display ads the way I want to.
I cover that in my blog entry: http://www.notthepainter.com/iad-admob-integration-with-a-dynamic-uiview/
Here is the text of the blog entry so it is preserved here, just in case my blog goes away someday.
I’ve released 2 apps both with iAds. I used Apple’s BannerView sample code to implement this. Basically, in your delegate you don’t set root to your expected root UIViewController but rather you set root to a BannerView which contains your real root. When an iAd is available, your main view shrinks and the iAd is displayed at the bottom. When an ad isn’t available, your view expands to its “normal” size.
This worked very well in testing so I released both apps to the app store. They’re Done Yet? and Wheelin. However, when I first downloaded the versions from the store I was quite surprised to see no ads ever. It turns out that at least right now, iAd had a pretty horrible fill rate. So I wanted to show another ad when an iAd wasn’t available.
I found LARSAdController, an open source project by larsacus on GitHub. He makes ad integration very easy except for one thing. When you go down his quick development route you get the ads covering your view, it doesn’t shrink to accommodate the ad. This is a completely reasonable design decision, just not one I wanted.
So I decided to modify Apple’s BannerView to use LARSAdController. It was pretty easy.
The first thing you do is remove iAd from BannerView’s .h file and ad in the LARS TOLAdViewController class.
#import "TOLAdViewController.h"
#define KVO_AD_VISIBLE #"KVO_AD_VISIBLE"
#interface BannerViewController : TOLAdViewController
(Just ignore the KVO_AD_VISIBLE define for now, I’ll cover that later.) In the .m file also remove iAd and make these changes:
#implementation BannerViewController {
UIView *_bannerView;
UIViewController *_contentController;
BOOL isLoaded;
}
We changed _bannerView from an ADBannerView into a plain old UIVIew. ADBannerView also has a bannerLoaded property which we’ll have to replace with our isLoaded boolean. initWithContentViewController is also easy to modify.
// IAPHelper *sharedInstance = [//IAPHelper sharedInstance];
//if ([sharedInstance showBannerAds]) {
if (YES) {
_bannerView = [[UIView alloc] initWithFrame:CGRectZero];
} else {
_bannerView = nil; // not showing ads since the user has upgraded
}
Notice the commented out section. If you are using in-app purchases to transform an ad supported version into an ad free version you can do that right there.
At the end of the method well use Key-Value-Observing (KVO) to watch LARS and see when an ad is served or removed. (I’ll probably cover KVO in a future blog entry.)
[[LARSAdController sharedManager] addObserver:self
forKeyPath:kLARSAdObserverKeyPathIsAdVisible
options:0
context:KVO_AD_VISIBLE];
And the observing code:
- (void)observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object
change:(NSDictionary *)change
context:(void *)context;
{
if(context == KVO_AD_VISIBLE) {
NSNumber *isVisible = [object valueForKey:kLARSAdObserverKeyPathIsAdVisible];
if ([isVisible boolValue]) {
_bannerView.frame = [[LARSAdController sharedManager] containerView].frame;
isLoaded = YES;
} else {
isLoaded = NO;
}
}
[self.view setNeedsLayout];
[self.view layoutIfNeeded];
}
We save the frame of the new ad and also update the isLoaded variable. (Originally thought I would need to call setNeedsLayout and layoutIfNeeded but in practice I didn’t.) The mods to viewDidLayoutSubviews were also pretty straightforward. The only odd part was removing the references to ADBannerContentSizeIdentifierPortrait and ADBannerContentSizeIdentifierLandscape and just replacing that all with a single line:
bannerFrame.size = [_bannerView sizeThatFits:contentFrame.size];
And a few lines later you use the new isLoaded variable
if (isLoaded) {
Don’t forget to clean up your observer in dealloc:
-(void) dealloc;
{
[[LARSAdController sharedManager] removeObserver:self forKeyPath:kLARSAdObserverKeyPathIsAdVisible];
}
All that remains is to tell LARS about your ads in your app delegate:
[[LARSAdController sharedManager] registerAdClass:[TOLAdAdapterGoogleAds class] withPublisherId:#"a14e55c99c24b43"];
[[LARSAdController sharedManager] registerAdClass:[TOLAdAdapteriAds class]];
LARSBannerViewController *root = [[LARSBannerViewController alloc] initWithNibName:#"LARSBannerViewController" bundle:nil];
_bannerViewController = [[BannerViewController alloc] initWithContentViewController:root];
[self.window setRootViewController:_bannerViewController];
And that’s it. Now your app should show iAD or AdMob ads and your view will shrink to accommodate them.
Of course there’s a bug, I don’t know if this is in AdMob server or in LARS but when you are in Landscape mode on an iPhone the ad’s size and the reported size are different leaving a black bar at the bottom of the screen. I’ve pinged larsacus about it and will update this post when I know more.
I’ve forked LARSAdController and submitted the above sample code in a full project on my github.
After a few days, I was getting ready to call for support, and then the iAds started working. So I guess the answer is that there is potential for a lag to occur between an app going live and ads populating for that app.
Initially when the ads started coming in, the fill rate wasn't much above 50% and I was only seeing the one ad for iTunes Radio, but at least the ads had started working. Now fill rate is up to 67% and I'm seeing a bit more of a variety with the ads.
i just implemented a basic iad banner and on the xib file i dragged and dropped the bannerview on the bottom of the iphone and ctrl clicked file owner and dragged it to the adview. The issue is when I load it onto an iphone 5, the banner is only 3/4ths of the way down because the xib view is on iphone 4. Is there anyway i can avoid the xib view altogether and have some code that just puts the banner at the bottom no matter the device. This is my first time using iAds so i'm a bit new to it.
Thanks
In my viewController.m file here is a few lines of code, i'm assuming this is where the code would go if it's possible.
#synthesize adView;
- (void) bannerViewDidLoadAd:(ADBannerView *)banner {
[adView setHidden:NO];
}
- (void) bannerView:(ADBannerView *)banner didFailToReceiveAdWithError:(NSError *)error {
[adView setHidden:YES];
}
In viewDidLoad:
adView.frame = CGRectMake(0, self.view.frame.size.height-adView.frame.size.height, adView.frame.size.width, adView.frame.size.height);
Also check out Robotic Cat's comment, as he is correct.
Apple has some sample code that demonstrates the proper way to display banner-style iAds in your app. Check it out here. In particular, take a look at the ContainerBanner project.
I have a tab based application. I have created an iAd object in app delegate class and using it in my three view controller class. It's working good on second tab's screen and third tab's screen. On second tab there is a table view, when clicking the row of that table view i navigate to the new view where i have used the same code for iAd. On clicking the iAd, iAd screen opens in landscape mode and when closing the screen becomes black and log the following.
[ADHostWindowController supportsOrientation:]: message sent to deallocated instance 0x100bc740
I created the object in app delegate like this:
self.bannerView = [[ADBannerView alloc]init];
[self.bannerView setDelegate:self];
I'm adding banner in view controllers like this:
[[[self appdelegate] bannerView] setFrame:CGRectMake(0, hightofView-180, 768, 66)]
All my view controllers are in portrait but iAds always open in landscape mode.
This is working in iOs 6, but not with iOS 5 on iPad. How do I fix this?
My guess your problem is not related to iAds but rather to memory issues.
It seems that an object of class kind ADHostWindowController is being deallocated prematurely.
My advice would be to make sure that ADHostWindowController is not released i.e (retainCount>=1) before supportsOrientation: is called to it. (which is definitely after the iAd opens).
For diagnosis: Try logging the retain count of that ADHostWindowController (then maybe retaining it one more time) before opening an iAd and see what happens.
Take a look at TabbleBanner code in iAd sample from Apple: https://developer.apple.com/library/ios/#samplecode/iAdSuite/Introduction/Intro.html
I don't investigate it in detail, but you need to follow the Apple iAd guide:https://developer.apple.com/library/ios/#documentation/UserExperience/Conceptual/iAd_Guide/BannerAdvertisements/BannerAdvertisements.html
To create a ADBanner, in each UIViewController, add one to self.view
#property (strong,nonatomic) ADBannerView *bannerView;
- (void)viewDidLoad
{
[super viewDidLoad];
[self createADBanner];
}
- (void)createADBanner{
self.bannerView = [[ADBannerView alloc] initWithFrame:CGRectZero];
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
[self.bannerView setDelegate:self];
[self.view addSubview:self.bannerView];
}
For beginning, you need to modify bannerView size and setCenter if need to place it at top or bottom.
- (void)viewDidLayoutSubviewsj{
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)) {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
} else {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
}
}
And do the same when rotate:
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
} else {
self.bannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierPortrait;
self.bannerView.center = CGPointMake(self.view.center.x, self.view.frame.size.height - self.bannerView.frame.size.height/2);
}
}