How to do Orientation Detection even the device has locked orientation - objective-c

I wonder how to perceive orientation changes even if the device's current orientation is locked (by double clicking home button and pressing the grey orientation lock icon)
However, I've seen video taking apps (UIImagePickerController) that can perceive orientation changes and change its control orientation.
I know that for detecting the change, I can use:
- shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
- UIDeviceOrientationDidChangeNotification
but neither of those methods work if the orientation of the device is locked.

You could use the accelerometer to get the current orientation check this Detect iPhone screen orientation

Related

How to make only camera screen orientation in both landscape and portrait while others being lock to portrait

I have successfully made all the screens of my app locked in portrait orientation but the problem is arising that the camera screen with which we have to take pics is also locked to portrait.
Currently I am using android:screenOrientation="portrait" under activity tag in AndroidManifest.xml to lock to portrait.
My question is, can we make camera screen orientation to both portrait and landscape while other screens be locked to portrait?
You can use something like this:
react-native-orientation
This is what I have seen commonly used to lock orientation on a screen per screen basis.
Using android:screenOrientation="portrait" in AndroidManifest.xml locks the entire app to portrait mode. If you want only one screen to be landscape, you'll either have to use the package #Chevol mentioned, or listen to width/height changes using onLayout for each screen and lock the orientation in manually.

Is there a way to force the camera orientation to stay in portrait?

My app's orientation is set to portrait mode in tiapp.xml and the the window's orientation mode is also set to portrait. But when I open the camera, the orientation is not locked to portrait, it still rotates. Is there a way to lock this because I need to capture the photos only in portrait mode?
In the CameraOptionsType dictionary you pass as options to Ti.Media.showCamera you can set the autorotate boolean property: false locks the camera preview rotation.

Device orientation sometimes returns an unknown value when rotating too fast

I am implementing iAd on iPad, and since I'm creating everything programmatically, I need to manually move the frame of the ad every time the user rotates the screen.
I uses the notification center to detect when the user rotates the device.
The problem is, sometimes when I rotate the device too fast the orientation becomes "UIDeviceOrientationUnknown". In this case, how can I tell the screen orientation to adjust the ad position accordingly?
I do not wish to use auto-layout.
I normally ask the status bar for orientation, 'cause it's always either landscape or portrait, like so:
[UIApplication sharedApplication].statusBarOrientation. In any case, there are a few approaches. I recommend reading through this thread.

iOS Face Up Orientation Issue

Is there any way to differentiate between landscape and portrait when the device is sitting on a desk, i.e. UIDeviceOrientationFaceUp? I have two different xib files that I switch between based on the way the user is holding the device. But the problem arrises when I hold the device in landscape, and then place the device down. The device remains in landscape, but will load the portrait xib file. The problem would be opposite if in my coding I coupled the UIDeviceOrientationFaceUp with the landscape orientations: then I would have my landscape view showing when the device is still in portrait.
Is there any way to be able to figure out if the device is still showing landscape or portrait? I have tried checking frame width, but it claims it is 768 even if the device is sitting flat in landscape. And I can't force an orientation when the device goes flat, I hear thats the road to rejection on the App Store.
You can't do that. The accelerometer can't tell on which side of the phone the user is sitting when it's laid down on a table. You can measure rotation around it's axis using the gyroscope (and the compass), but that still doesn't tell you where the user is unfortunately.
There is one way to check it.
UIDeviceOrientation deviceOrientation = [[UIDevice currentDevice] orientation];
UIInterfaceOrientation statusBarOrientation =[UIApplication sharedApplication].statusBarOrientation;
Use the first one to check if the device is in faceup and second one will tell you if the device is in portrait or landscape.

iPad view in incorrect orientation after dismissMoviePlayerViewControllerAnimated

My iPad app displays a movie full screen using the convenient MPMoviePlayerViewController class. I present it like this:
[self.hostController presentMoviePlayerViewControllerAnimated:playerViewController];
And later, when notified that playing is done, I dismiss it like this:
[self.hostController dismissMoviePlayerViewControllerAnimated];
It works fine, except when the user rotates the iPad during movie playback:
1- The iPad is in vertical orientation. My view is vertical.
2- The user starts the movie in vertical orientation. The player is vertical.
3- The user rotates the iPad to the horizontal orientation.
4- The player switches to its horizontal orientation. so far so good.
5- The movie stops, the player is dismissed, my reappears, the iPad is still horizontal, but my view has stayed in the vertical orientation is was in step 1. Now it looks sideways.
Of course, if the user then rotates the iPad, it's back to normal. My view then rotates normally as the iPad rotates.
Did anyone ever encounter that? An easy fix?
Thanks.
I've encountered this numerous times and it appears to be an Apple bug (and have reported it as such).
The only way (I've found) around this is to listen to UIDeviceOrientationDidChangeNotification and UIApplicationDidChangeStatusBarOrientationNotification notifications. Use the relative timestamp on these notifications; if they both occur within a second of each other, you can be sure that the status bar change is a result of the user switching orientations and not the media SDK changing the status bar orientation. Then, when the movie is finished, you can tell your view controller that it should rotate to landscape.