on iPad ios 9+, with objective-c : - lock the orientation outside of your app - in code: how to detect when the device changes the orientation?
I have tried all possibilities:
1) try to catch UIDeviceOrientationDidChangeNotification event:
- (void)subscribeOrientationChangeEvent { [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(orientationChanged:) name:UIDeviceOrientationDidChangeNotification object:[UIDevice currentDevice]]; } - (void) orientationChanged:(NSNotification *)note { NSLog("Device rotated"); }
2) override viewWillTransitionToSize method
- (void)viewWillTransitionToSize:(CGSize)size withTransitionCoordinator:(id)coordinator { [super viewWillTransitionToSize:size withTransitionCoordinator:coordinator]; NSLog("Device rotated"); }
3) use KVO to see if the value orientation of [UIDevice currentDevie]
4) use KVO to see if the value statusBarOrientation of [UIApplication sharedApplication]
5) set Require FullScreen for the setting StatusBarStyle
reference: link
apply this setting and combine with all above attempts, but all failed.
6) using Accelerometer (CMMotionManager)
Any advice? thanks a lot