{"id":642,"date":"2012-06-07T14:28:56","date_gmt":"2012-06-07T14:28:56","guid":{"rendered":"http:\/\/www.sitekickr.com\/blog\/?p=642"},"modified":"2012-06-07T14:28:56","modified_gmt":"2012-06-07T14:28:56","slug":"admob-iphone-apps-device-orientation","status":"publish","type":"post","link":"https:\/\/www.sitekickr.com\/blog\/admob-iphone-apps-device-orientation\/","title":{"rendered":"AdMob iPhone Apps and device orientation"},"content":{"rendered":"<p>We were closing in on the release of a new iPhone app, when we realized that the landscape orientation really isn&#39;t suited well for an advertisement. If you&#39;ve dabbled with <a href=\"http:\/\/www.google.com\/ads\/admob\/\">AdMob<\/a>, you know by know that there&#39;s no such thing as a full-width landscape ad. AdMob serves the add as if it was designed for landscape view, leaving it up to you to position it how you like.<\/p>\n<p>There are some tips on this throughout the web, but as a <a href=\"http:\/\/phonegap.com\/\">PhoneGap<\/a> user, I started to wonder how some users would know where to &quot;drop&quot; the code.<\/p>\n<p>Basically, we are overriding existing methods provided by the app framework. So, although you won&#39;t see a <em>willAnimateRotationToInterfaceOrientation<\/em> method in your <em>MainViewController.m<\/em>, you can simply add it to override the default.<\/p>\n<p>I&#39;ve pasted some code below which does a few things:<\/p>\n<ol>\n<li>Forces ads to the bottom<\/li>\n<li>Hides the status bar in landscape mode<\/li>\n<li>Puts ads in &quot;test&quot; mode<\/li>\n<li>Sets the preferred gender for ad targeting to female<\/li>\n<li>Hides ads in landscape mode<\/li>\n<li>Demonstrates how to position ads in landscape mode (commented out)<\/li>\n<\/ol>\n<p>&nbsp;<\/p>\n<p><code>- (void) webViewDidFinishLoad:(UIWebView*) theWebView <br \/>\n\t{<br \/>\n\t&nbsp;&nbsp;&nbsp; \/* existing code *\/<br \/>\n\t<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; bannerView_ = [[GADBannerView alloc] initWithFrame:CGRectMake(0.0,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb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;&nbsp;&nbsp; GAD_SIZE_320x50.height)];<br \/>\n\t&nbsp;&nbsp;&nbsp; bannerView_.adUnitID = MY_BANNER_UNIT_ID;<br \/>\n\t&nbsp;&nbsp;&nbsp; bannerView_.rootViewController = self;<br \/>\n\t&nbsp;&nbsp;&nbsp; [self.view addSubview:bannerView_];<br \/>\n\t&nbsp;&nbsp;&nbsp; <br \/>\n\t&nbsp;&nbsp;&nbsp; GADRequest *request = [GADRequest request];<br \/>\n\t&nbsp;&nbsp;&nbsp; request.testing = YES;<br \/>\n\t&nbsp;&nbsp;&nbsp; request.gender = kGADGenderFemale; \/\/ until we have a login with gender info<br \/>\n\t<\/code><\/p>\n<p><code>&nbsp;&nbsp;&nbsp; \/\/ use this if you want to show landscape ads, and center them at the bottom<br \/>\n\t&nbsp;&nbsp;&nbsp; \/\/[bannerView_ setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin|UIViewAutoresizingFlexibleLeftMargin|UIViewAutoresizingFlexibleRightMargin];<br \/>\n\t&nbsp;&nbsp;&nbsp; [bannerView_ loadRequest:request];<br \/>\n\t&nbsp;&nbsp;&nbsp; <\/p>\n<p>\t&nbsp;&nbsp;&nbsp; \/* existing code *\/<br \/>\n\t}<\/p>\n<p>\n\t- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)newInterfaceOrientation duration:(NSTimeInterval)duration {<br \/>\n\t&nbsp;&nbsp;&nbsp; BOOL hide = (newInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || newInterfaceOrientation == UIInterfaceOrientationLandscapeRight);<br \/>\n\t&nbsp;&nbsp;&nbsp; [[UIApplication sharedApplication] setStatusBarHidden:hide withAnimation:UIStatusBarAnimationNone];<br \/>\n\t&nbsp;&nbsp;&nbsp; CGRect mainFrame = [[UIScreen mainScreen] applicationFrame];<br \/>\n\t&nbsp;&nbsp;&nbsp; [self.view setFrame:mainFrame];<\/p>\n<p>\t&nbsp;&nbsp;&nbsp; if (newInterfaceOrientation != UIInterfaceOrientationLandscapeLeft &amp;&amp; newInterfaceOrientation != UIInterfaceOrientationLandscapeRight) {<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bannerView_.frame=CGRectMake(0.0,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; self.view.frame.size.height - GAD_SIZE_320x50.height,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GAD_SIZE_320x50.width,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GAD_SIZE_320x50.height);<br \/>\n\t&nbsp;&nbsp;&nbsp; }<\/p>\n<p>\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; \/* keep ads hidden in landscape view for now<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; bannerView_.frame=CGRectMake(0.0,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0.0,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 480.0,<br \/>\n\t&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; GAD_SIZE_320x50.height);<br \/>\n\t&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; *\/<br \/>\n\t}<br \/>\n\t<\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>We were closing in on the release of a new iPhone app, when we realized that the landscape orientation really isn&#39;t suited well for an&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"amp_status":""},"categories":[132],"tags":[181],"_links":{"self":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/642"}],"collection":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/comments?post=642"}],"version-history":[{"count":1,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/642\/revisions"}],"predecessor-version":[{"id":643,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/posts\/642\/revisions\/643"}],"wp:attachment":[{"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/media?parent=642"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/categories?post=642"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.sitekickr.com\/blog\/wp-json\/wp\/v2\/tags?post=642"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}