Locker doesn't work on iOS 11. (but works great on Android)
See original GitHub issueiOS: 13.1 React: 16.9.0 React Native: 0.61.5 react-native-orientation-locker: 1.1.8
componentDidMount() {
Orientation.lockToLandscapeLeft();
}
componentWillUnmount() {
Orientation.lockToPortrait();
}
**The above locker function works great on Android but not on iOS
In iOS, when entering componentDidMount(), the orientation is changed to the landscape and then changed back to the original one. (isn’t locked to landscape)
I wonder the following native code line has a wrong or not.**
// Orientation.m
...
- (void)lockToOrientation:(UIInterfaceOrientation) newOrientation usingMask:(UIInterfaceOrientationMask) mask {
// set a flag so that no deviceOrientationDidChange events are sent to JS
_isLocking = YES;
NSString* orientation = @"orientation";
UIInterfaceOrientation deviceOrientation = _lastDeviceOrientation;
[Orientation setOrientation:mask];
UIDevice* currentDevice = [UIDevice currentDevice];
[currentDevice setValue:@(UIInterfaceOrientationUnknown) forKey:orientation];
[currentDevice setValue:@(newOrientation) forKey:orientation];
//----------------- changed to landscape------------------------
// restore device orientation
[currentDevice setValue:@(deviceOrientation) forKey:orientation];
//--------------but changed back to original one------------------
[UIViewController attemptRotationToDeviceOrientation];
[self sendEventWithName:@"lockDidChange" body:@{orientation: [self getOrientationStr:newOrientation]}];
_isLocking = NO;
}
What is the solution?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:6 (1 by maintainers)
Top Results From Across the Web
How to Fix iPhone Auto Lock Not Working - iMobie Inc.
Wondering how to fix iPhone auto lock not working in iOS 12/11/10? Here we'll show you some quick tips to fix the problem...
Read more >Music widget permanently on lock screen? - Apple Developer
I was having the same issue. Here's what I did: Firstly, closed all the running apps from the background by double tapping the...
Read more >iOS 16 Problems and Bugs with Fixes in 2022 - Tenorshare
iOS 16 Lock Screen Depth Effect Not Working. iOS 16's depth effect is a great new feature, but if iOS 16 lock screen...
Read more >Common iOS 11 Problems, How-To Fix - AppleToolBox
The best course of action to fix this issue is to let your iPhone or iPad stay disconnected from a power source. Let...
Read more >[Fixed] 8 Ways to iPhone Auto Lock Not Working -iOS 14/15 ...
Fix 1: Re-enable Auto-Lock on iPhone/iPad · Fix 2: Turn Off AssistiveTouch on Your iPhone · Fix 3: Disable Low Power Mode if...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
I was having the same issue. Experiencing it on v1.1.8. Downgraded to v.1.1.7 and same thing.
The problem was copy/paste. When I added the lines to my AppDelegate.m file I accidentally included a plus sign on the first line when it should have been -
+(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return [Orientation getOrientation]; }
The app still compiled and ran no problem but the orientation locks would flip back to portrait immediately. After removing the plus sign and switching it to -, it held its locked position. I can reproduce the issue by adding the plus sign back in.
-(UIInterfaceOrientationMask)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window { return [Orientation getOrientation]; }
Double-check your AppDelegate.m file and make sure none of the plus signs came along for the ride when you copy/pasted.
Be sure to place this function before the last “end”