Opening iAds in landscape app screws the whole orientation - ios

My app runs in landscape mode. I do not support portrait orientation and, in all of the screens, if I rotate the device to portrait, everything is, as expected, in landscape.
I am displaying iAd banners and they look good, they rotate when they should along with their superviews. Everything is ok regarding banner display.
The problem is that when I tap on them and the actual ad is opened, the whole app orientation gets screwed. The iAD is opened in portrait mode, its position is wrong, offset to half of the screen, and it messes with the whole app orientation, taking it to an unsupported and weird looking portrait mode.
Any thoughts on how to avoid this?
Some app details:
iOS6
Landscape mode only
Cocos2d + UIKit for some screens
The integration code for iAds is standard, as explained on the iAds programming guide
The app root view controller is a simple UIViewController, no navigation controllers or anything like that.
It doesn't use autolayout.

Me also used iAds in Cocos2d-landscape game. For me its working.
Here is files hosted: Download
-(void)showBannerView
{
_adBannerViewIsVisible = true;
AppController * myDelegate = (((AppController*) [UIApplication sharedApplication].delegate));
[myDelegate.navController.view addSubview:self.adBannerView];
if (self.adBannerView)
{
[UIView animateWithDuration:0.5
delay:0.1
options: UIViewAnimationCurveEaseOut
animations:^
{
CGSize s = [[CCDirector sharedDirector] winSize];
CGRect frame = self.adBannerView.frame;
frame.origin.y = s.height - frame.size.height;
frame.origin.x = (s.width/2.0f - frame.size.width/2.0f);
self.adBannerView.frame = frame;
}
completion:^(BOOL finished)
{
}];
}
}

You need to set the AdBannerView to display landscape-ads only:
adBannerView.requiredContentSizeIdentifiers = [NSSet setWithObject:ADBannerContentSizeIdentifierLandscape];
adBannerView.currentContentSizeIdentifier = ADBannerContentSizeIdentifierLandscape;
This way, ads that don't support landscape should not be loaded. Be aware that this will result in a drop of your fill-rate.

Well this issue screwed me up for 2 days
and I even gave up on iAd
untill I ran to the same issue with gamecenter authentication, that always opens in portrait and screws the whole orientation for the app in the same manner .
However the solution for the game center I found almost immediately in google search.
I tried to apply the same solution for iAd and it worked.
the main idea is to let your app to run in both
portrait and landscape (in info plist of the app)
Then in your view controller to set the preffered orientation to landscape right , allow rotation of orientations and support both landscape and portrait.
The detailed answer is here:
Gamecenter authentication in landscape only Cocos2d with CCLayer for iOS 6
Special thanks to Sylvan !

Related

ViewController orientation on external monitor

I have an iPad kiosk app that displays video on an external monitor connected via an HDMI cable. The device orientation is set to Landscape Left or Landscape Right in the apps general settings. I want the app to be displayed in landscape on the iPad and on the external monitor. When I run the app in iOS7 the external monitors view controller is displayed correctly in landscape orientation, but when run under iOS 8 the external monitor's view controller is rotated 90 degrees counterclockwise, into portrait orientation.
How do I force the external monitor to the correct landscape orientation? What has changed between iOS 7 and 8 to cause this behavior?
I've had a similar issue with a landscape-only iPad app that supports airplay. On the iPad screen, everything was working fine, but on the external display, starting # iOS 8.0, orientation issues started happening. I tried many things, what ended up helping was these two fixes:
On the shouldAutorotate method of your ViewController, return NO.
Implement the application:supportedInterfaceOrientationsForWindow: method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)_window
{
if ([UIScreen mainScreen] == _window.screen || !_window)
{
return UIInterfaceOrientationMaskAll;
}
else
{
return UIInterfaceOrientationMaskPortrait;
}
}
The second part of the fix may require some changes on your side, since you're not using AirPlay, but I hope it can help lead you to the right solution. Good Luck!

iPad App is not launced in landscape mode and getting black screen portion when launching in landscape mode

I have a universal iOS app and currently I am developing it for iPad.
When I am launching the app in the portrait mode app launches fine. But when I launch in landscape mode, portion of the screen becomes back and the app is not launched in landscape mode. I have used
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll; }
- (BOOL)shouldAutorotate {
return YES;}
but the app is not launching in landsape mode and having a black screen portion. I have attached a screen shot as well.. What is the problem here and how to get rid of this?
Try this, write this in ViewDidLoad, We need to set the insets for self.view
if ([self respondsToSelector:#selector(edgesForExtendedLayout)])
{
self.edgesForExtendedLayout=UIRectEdgeNone;
}
Since your view is rotated correctly (the text is upright) you can assume that this problem is not a rotation problem but instead a problem with your layout code/interface builder.
To solve this make sure you pinned your content view to all edges of his superview
I had the same problem when iOS8 comes out. With iOS7 all worked fine. After spending a lot of time try to solving i just find that replacing the "launch xib" with a storyboard fix my problem.
So try to add a storyboard, put your actual initial xib into and restart. Don't forget to specify the inizial storyboard into your project's info.
NB you probably have this problem on iPhone6+ as well because it is capable of running springboard in landscape.
I rarely (pretty much never) use storyboards or nibs, so I've had this problem since iOs7 in applications which support rotation. I set up my viewControllers in loadView or viewDidLoad and at that point the viewController does not know the interfaceOrientation. Because I usually handle rotation programatically as well I just do something like this in viewWillAppearAnimated:
{
BOOL landscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication]statusBarOrientation]);
BOOL ios8 = NSClassFromString(#"UIPopoverPresentationController")!=NULL;
if (landscape&&ios8) {
[self willRotateToInterfaceOrientation:[[UIApplication sharedApplication]statusBarOrientation] duration:0.0];
}
}
Just solved similar problem by setting UIMainStoryboardFile for my app (although this has no side effects on my app as I am setting my ViewControllers in code). So setting main storyboard file has fixed this for iOS 8 through 10.
So set both launch screen and your main interface storyboards.
Setting NSMainNibFile have not fixed that problem for me. Only storyboards.
Main storyboard should contain at least initial view controller that could be empty.
In the appDelegate, set:
[self.window setFrame:[[UIScreen mainScreen] bounds]];
in the didFinishLaunchingWithOptions

Forcing Portrait Mode in a UIPageViewController on iPad

I have an iPad app which supports Portrait and Landscape in the entire app. This is an iOS 7 and iOS 8 version of an app.
The app is a UITableViewController with multiple segues to a different set of UIViewControllers. I have one option in the app to show the Tutorial again and I have created the images in a Portrait mode only orientation because it just wouldn't make too much sense (or look good in Landscape).
With this in mind, the tutorial is in the form of images loaded into a UIPageViewController. The images are loaded in the viewDidLoad and the buttons and layout work really well.
Issue
I want to restrict the UIPageViewController to be in a Portrait orientation only.
Currently, I have:
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
[[UIDevice currentDevice] setValue:
[NSNumber numberWithInteger: UIInterfaceOrientationPortrait]
forKey:#"orientation"];
}
That works to some extent. If the device is in Landscape mode and the tutorial is invoked, it rotates it to Portrait.
However, if the device is in Portrait and I rotate it to Landscape after invoking the Tutorial, the tutorial then rotates.
How exactly do I prevent this view from rotating in my custom UIPageViewController class, so that it never rotates to Landscape whether it's at the start, middle, or end of the tutorial.
Any guidance on this would really be appreciated.
Take a look at UIViewController docs for Orientation support, specifically shouldAutorotate: and supportedInterfaceOrientations- https://developer.apple.com/library/ios/DOCUMENTATION/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/supportedInterfaceOrientations
My first guess would be you would want to set the value like you're doing now, and then override shouldAutorotate in your custom UIPageViewController subclass and return NO.
However, be aware you could get hit in the review process for HIG compliance, because your app claims to support all orientations, but parts of it don't. Obviously this is totally up to the reviewer and whether or not they catch it as plenty of other apps do this.

Is this an iOS 8 Bug (orientation issue on rotation)?

since iOS 8 my App runs quite good, but I found a Problem while testing this app.
It just happens on iPad and only if I launch the app in landscape mode. If it launches in Portrait everything is right(no rotation issues). If i rotate the Device (simulator or real device) the view rotates out of the screen and just shows a Cut of the real view and the rest is black.
Anyone else did notice such a bug? How can I fix it?
Had similar problem. Surprisingly the fix was to comment out all the code related to self.window on Appdelegate.
Commented initialising of self.window and its assignment. Set the initial view in storyboard in Attributes inspector by checking "Is Initial View Controller" checkbox.
New Better Solution
Commenting self.window was causing other issues. Instead the below code is best:
- (void)applicationDidChangeStatusBarOrientation:(NSNotification *)notification
{
[UIViewController attemptRotationToDeviceOrientation];
}
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
BOOL landscape = (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight);
NSLog(#"Currently landscape: %#, width: %.2f, height: %.2f",
(landscape ? #"Yes" : #"No"),
[[UIScreen mainScreen] bounds].size.width,
[[UIScreen mainScreen] bounds].size.height);
And the results are:
For iOS 8+
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 568.00, height: 320.00
and for iOS 7-
Currently landscape: No, width: 320.00, height: 568.00
Currently landscape: Yes, width: 320.00, height: 568.00
It seems like there is a change in the way height and width of the screen is handled while in portrait and landscape from ios8 onwards.
Check this link
Is [UIScreen mainScreen].bounds.size becoming orientation-dependent in iOS8?
UPDATE - We found a fix:
I found the answer to our problem which as described below appeared to be exactly the same as yours. One of our other developers noticed an "unexpected nil in main window" when attempting to tap on the far right of the screen. This led me to do a new search and I found this thread on stackoverflow that actually contained the answer to our problem.
( here is the link to the question which help my answer: unexpected nil window in _UIApplicationHandleEventFromQueueEvent )
The actual answer came from frankish who suggested opening the main.xib (or main storyboard) and clicking on the Window in that and making sure that the "Visible at Launch" and "Full screen at Launch" properties are checked (set to true.)
In our case, it was JUST the "Full screen at Launch" property that needed to be set, but setting this fixed the rotation problem we were seeing AND it fixed an issue where when launching on iPad in landscape the far right of the screen was not touchable.
END UPDATE - (original non-answer below)
My answer isn't an answer, but I have run into the exact same issue. On rotate in our app, when building with Xcode 6, I see the exact same rendering issue as the the screenshots on this question. The exact same out of position rotate with black bars at the side and bottom. (Our app on iPhone doesn't support any rotation so we don't see the issue on iPhone. On iPad we support landscape left and landscape right. When rotating from one to the other, when the iPad does it's standard rotation animation, it will rotate out of position (showing the black bars) when going one way and then rotate back into proper position when going back to the other supported orientation. I don't believe it's related to any custom positioning or animation code. It happens with every screen, including the splash screen. It appears to be related to the built in Apple screen rotation. Obviously not every project has this issue in iOS but I have not come across the particulars that are causing this issue. I spent all day yesterday researching the issue and going through our code and I have nothing.
One piece of additional info. If I build with Xcode 6 and run on a device with iOS 7 then there is not issue. This issue ONLY happens when I build with Xcode 6 and run on a device with iOS 8.
Here is a link to my own question posted yesterday about this issue. (I did not come across this question until after I'd posted my question.)
Building project with Xcode 6 (iOS 8 SDK) causes landscape rotation rendering issue on iPad
I found this to be an issue when I had multiple windows in my application. By setting a breakpoint on -[UIWindow setFrame:], I was able to see that upon rotation, the system was giving me giving me an erroneous frame size and position. You can get around this by manually setting your frame to equal [UIScreen mainScreen] bounds] which seems to be correct if you running on iOS7+ and compiling with Xcode6. I found that doing this in -[UIWindow becomeKeyWindow] worked well for me:
- (void)becomeKeyWindow {
[super becomeKeyWindow];
self.frame = [UIScreen mainScreen].bounds;
}

iOS 6 iAd orientation issues - iAds rotate my portrait only app to landscape and leaves it that way

I have created an iOS6 "Single View" iPhone application.
The application is portrait only.
I added iAds to the application.
I add additional views to the application like this:
if (self.menuChoiceInstance == nil) {
self.menuChoiceInstance = [[NJDViewControllerMenuChoice alloc] initWithNibName:#"NJDViewControllerMenuChoice" bundle:nil];
self.menuChoiceInstance.delegate = self;
}
[self.view addSubview:self.menuChoiceInstance.view];
Everything seemed to work fine.
I then added universal/iPad support. Including the following line when I add my subview:
[self.menuChoiceInstance.view setFrame:CGRectMake(0, 0, self.view.frame.size.width,
self.view.frame.size.height)];
Now I get issues with iAds.
When pressing an iAd on the the rootViewController the iPad rotates to landscape. It then rotates back to portrait on closing the advert.
However pressing an iAd on the iPad on a subview makes the view rotate to landscape, and it stays landscape on closing. This destroys my user interface.
This iPad issue is the main problem, but I now also occasionally see issues with the iPhone view too, which could be related.
The iAd banner at the bottom of the screen showing the test ads sometimes has giant text and icons within it, making them overlap each other and impossible to read. Pressing the iAd rotates the phone to landscape (again in a portrait only app), yet the iAd shows the advert as if it is still portrait, with stretched content that goes off the bottom of the screen.
Similar issue here. Hard to find out what was it because i used a third party API. My problem was solved by adding my UIView as child to the rootViewController. Then my view begin to respond all main window changes. Just a line like this somewhere along viewDidLoad of myUIViewController (or as many as you have).
[myUIWindow.rootViewController addChildViewController:self];
Similar issues...
iAd Landscape Strange View Behavior
Force ADBannerView to rotate (Not "orientation" but actual transform)
iAd banner rotates my view to landscape
I believe the issue was caused by the fact that I was adding subviews onto my current view, rather than switching views.
I have changed the code that adds a subview from:
[self.view addSubview:self.statsInstance.view];
to code that presents a view.
[self presentViewController: self.settingsInstance animated:YES completion:nil];
This seems to have resolved my issue, as well as some other issues with iAd delegation methods (bannerViewActionDidFinish was called straight after the ad loaded.)

Resources