iOS 6 Game Center Crash on Authentication in landscape mode cocos2d - crash

I have developed a game in cocos2d and all game screens are in Landscape mode. I am trying to implement game Center but getting crash on authentication. I did not find answer of similar type of issues. please suggest right approach...
Crash issue:-'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'
I tried below solution but it also disturb game orientations, game starts work in portrait mode also, that i don't want:-
(NSUInteger)application:(UIApplication*)application
supportedInterfaceOrientationsForWindow: (UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}

Make sure you selected landscape in Xcode summary page.
Also add these code in your viewcontroller
-(NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskLandscape;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}
Update this function in AppDelegate:
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskLandscape;
}

the solution for that is short, i spent a lot of time before finding it:
in the AppDelegate in the method didFinishLaunchingWithOptions put this line:
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait];
obviously before call the login game center method, i put that before create the UIWindows

Related

Best way to Supporting Multiple Interface Orientations - iOS8

I have been trying to convert few old apps written in objC long ago in iOS4 which support multiple ViewController with different orientation.
(BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
Above Method is called in app delegate from ViewController and Desire Orientation was set but seems stopped working with iOS8.
I have tried number of solution like creating Category of UINavigation controller etc, but nothing seems working with iOS8.
What is best approach to handle Multiple Orientation for both iPhone and iPad.
Furthermore, I am not using Storyboard with size classes, in plist i am only supporting portrait orientation.
Check all the orientation you want to support in device.
For that go to Project target-> Deployment info -> Device orientation-> Tick mark the desired orientation.
From iOS 6 onwards, you've to use.
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation];
if (orientation == UIInterfaceOrientationPortrait) {
// your code for portrait mode
}
return YES;
}
Refer to shouldAutorotateToInterfaceOrientation not being called in iOS 6

launching a modal view controller to work around the orientation "lock" of tab bar and nav VCs?

I have an iPhone app with a root view controller (VC) of UITabBarController (set to portrait orientation) with several tabs, one of which is a simple UIViewController. In that UIViewController is a single button - "Play Video", which, when clicked opens a modal view of the video (and automatically starts playing the video). The video view is a UIWebView in a UIViewController. I've been trying to get the Web View's VC to change orientation to landscape but have not had any luck.
I've looked around and understand that if you have a Tab Bar or a Nav controller, all children VCs will be the same orientation as the parent - makes sense. This is why I made the web view's VC modal, hoping this is a way around the orientation issue.
My question is: is this accurate - that using modal will not require the web view VC to be portrait and can respond to the shouldAutorotateToInterfaceOrientation method (even though I have not yet been able to get it to work)?
BTW, using iOS 6.
Thanks in advance.
Apparently in ios6 and above, the way rotation works is different. So what you have to do is the following
In your .plist support all 4 orientations.
Subclass the UITabBarController (for e.g: CustomTabBarController)
In the CustomTabBarController put the following lines of code
-(NSUInteger)supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationPortrait;
}
In your app delegate or where ever you are initializing UITabBarController, replace those instances with CustomTabBarController instances.
In your modal controller put the lines
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation
{
return UIInterfaceOrientationLandscapeLeft;
}
-(BOOL)shouldAutorotate{
return NO;
}
And it should all work.
Apparently the trick, I found is that, UITabBarController will not listen to your instructions. It will support all the orientations you mention in the .plist.
There fore you have to subclass it.
I tried doing all of the above and it works fine. Do let me know and I can send you the code if you want.
Try this. Just have portrait set in the summary screen, then in the app delegate, implement this:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return UIInterfaceOrientationMaskAll;
}
In the tab bar controller (and no other rotation code):
-(BOOL)shouldAutorotate {
return NO;
}
And finally, in the modal view controller:
-(BOOL)shouldAutorotate {
return YES;
}
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskAll;
}

iOS6 autorotation confusion and support for iOS5

Since iOS6, I realize that the shouldAutorotateToInterfaceOrientation: method has been deprecated. Most of my app I would like the user to be able to rotate, which does work in iOS6 and 5 currently. But, I have a modal view that I ONLY want to be portrait, so I have added the following without it actually working (tested in simulator and device):
// Tell the system what we support
- (NSUInteger)supportedInterfaceOrientations {
return UIInterfaceOrientationPortrait;
}
// Tell the system It should autorotate
- (BOOL) shouldAutorotate {
return NO;
}
// Tell the system which initial orientation we want to have
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
Why isn't this code preventing my modal from rotating?
How can I still support the iOS5 method as well as the iOS6 methods without crashing for users on iOS5?
You have to embed the presented vc in a navigation controller where you can set the preferred orientation.
https://stackoverflow.com/a/12522119
You missed to but this line inside your -(void)viewDidLoad method
[[NSUserDefaults standardUserDefaults] setBool:YES forKey:#"UIApplicationSupportedInterfaceOrientationsIsEnabled"];
I hope this can help you

Launching an app in landscape under ios6 while supporting all orientations

I have done a ton of research and am still unable to find a solution for this...
I have an app that supports all orientations. When the app is run on the iPad I want it to launch in landscape mode. The user can then rotate to portrait if they choose. Under ios5, I accomplished this by setting supported orientations for the iPad in the info.plist file to lansdcape left. I then used the shouldAutorotateToInterfaceOrientation method in each view controller to allow all orientations when the app was running.
I then changed my code to support the new orientation methods for iOS6 but when I ran the app on the iPad, it was not rotating at all. I then changed the info.plist file to support all orientations for the iPad. This solved the problem with the iPad not autorotating but now I can't figure out how to force the app to initially open in landscape mode. Any ideas?
Thanks in advance for any help you can give!
I ran into something similar recently, although my problem was that I wanted to force portrait in an iPhone app, but allow movies to play in landscape. Here's what I did:
Add a property to my app delegate to store the orientations I want to allow:
#property (nonatomic, assign) NSUInteger supportedOrientations;
Then in the app delegate, implemented the new iOS 6 method:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window {
return supportedOrientations;
}
On app launch I forced portrait:
self.supportedOrientations = UIInterfaceOrientationMaskPortrait;
And then once the app had finished launching and I'd shown my root view controller, I set it to support both orientations:
self.supportedOrientations = UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskLandscape;
I had to add the additional step of subclassing my UINavigationController to prevent rotation after that, because I wanted to allow landscape video but not rotation:
- (BOOL)shouldAutorotate {
return FALSE;
}
But that's just for info. You won't need that

Interface Orientation won't change to Landscape on App Launch

i stuck on a problem that drives me crazy!
I have an iPad application starting with a TabBarViewController. Every Tab has it's own ViewController and nib-file.
To make interface orientation possible I added all orientations to my info.plist and subclassing my TabBarController to set:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
Every View is autoresized and formatted well for displaying the right Orientation if I rotate the Interface. If I test it in the simulator, everything looks fine and I can rotate between the Orientations.
Now the point that drives me crazy:
If I launch the App in Portrait Mode, all works fine.. but if I launch in Landscape, I get an error and my Interface orientation seems still to be Portrait, while the Simulator is in Landscape Mode!!
The Error:
2011-05-24 21:50:15.011 Project[57995:207] Using two-stage rotation animation. To use the smoother single-stage animation, this application must remove two-stage method implementations.
I checked for Orientation like this:
-(void)viewWillAppear:(BOOL)animated{
UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if ((orientation == UIInterfaceOrientationLandscapeLeft) || (orientation == UIInterfaceOrientationLandscapeRight)) {
NSLog(#"Orientation: Landscape");
}
else{
NSLog(#"Orientation: Portrait");
}
}
The Log says it is in "Landscape" Mode if I launch in Landscape, but if I change tab to another it looks terrible because the View is displayed in Portrait mode instead.
On change back to the start-view where i asked for Orientation… the log displays "Portrait"… but the Simulator is still Landscape!
I can't figure out why the Orientation is Portrait on start,…
even if I start in Landscape…
Any idea how to solve this problem?
Ok. So the documentation says viewWillAppear: is called prior to all animations. And when your app starts, its initial orientation is Portrait. Based on what your orientation is, it then rotates to that orientation. Since it animates to the orientation off screen, this must be called after viewWillAppear:/ So when viewWillAppear: is called, its still in Portrait. I tested this myself.
I solved the problem!
Simply used this in viewWillAppear method of all my Views, to make it work when started in Landscape mode:
if(([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeLeft) || ([[UIApplication sharedApplication]statusBarOrientation] == UIInterfaceOrientationLandscapeRight)){
//Landscape View
}
else{
//Portrait View
}
Works fine for me!