I have a problem. I solved this problem here (https://stackoverflow.com/questions/34870418/app-crashes-if-the-orientation-is-changing-in-uiwebview)
But now my app is ignoring my orientation
. If I entered the login data and the new website is loaded but the orientation
is not the same the app is ignoring the new orientation
.
dispatch_async(dispatch_get_main_queue(), ^{
NSNumber *value = [NSNumber alloc];
NSLog(@"Inside!");
NSLog(@"Orientation: %@", [self orientNr]);
if( [[self orientNr] isEqualToNumber:@1] ) value = [NSNumber numberWithInt:UIInterfaceOrientationUnknown];
else if( [[self orientNr] isEqualToNumber:@2] ) value = [NSNumber numberWithInt:UIInterfaceOrientationLandscapeRight];
else if( [[self orientNr] isEqualToNumber:@3] ) value = [NSNumber numberWithInt:UIInterfaceOrientationPortrait];
[[UIDevice currentDevice] setValue:value forKey:@"orientation"];
});
The app is going inside this block because I got the two logs at my console. The orientation
is the correct one but it won't execute.
Why is the app ignoring my orientation
? If I restart the app it's always portrait although it should be landscape.
In my file plist.info I have configured Supported Interface Orientation
I've tested you code in a new project and it works. Please check on your info.plist if you configured "Supported Interface orientations" entry correctly:
There's a alternate way to force the rotation:
#import <objc/message.h>
Then when you want to force landscapeLeft orientation use this:
((void (*)(UIDevice *, SEL, int))objc_msgSend)([UIDevice currentDevice],@selector(setOrientation:),UIInterfaceOrientationLandscapeLeft);