Capture Image Orientation Issue - ios

This is regarding image orientation when captured with the device rotation lock on.'
self.photoOutput.connection(with: AVMediaType.video)?.videoOrientation = self.stillImageOrientation
I have self.stillImageOrientation listening to status bar orientation
UIApplication.shared.statusBarOrientation
However, when the user activates device rotation lock and rotates the device, captured photos get saved in the wrong orientation.
I expected this might solve the issue:
UIDevice.current.orientation
That also stops changing after the device rotation lock.
I noticed the native camera app still registers proper orientation even after the device rotation lock. Is there a way to achieve this?

Related

How intercept ios rotation when physical device block is enabled (Swift)?

I need to straight up the image taken by custom camera capture view but with physical device rotation block enabled it seem impossible.
physical device rotation block
UIDevice.current.orientation works only with device rotation "unlocked". Someone can help me with this tedious bug? Thanks.
Unfortunately there is no way to unlock rotation while physical block enabled, but you can turn landscape mode as your main in project settings
landscape mode as main

Ask permission to unlock screen orientation in Swift

I'm working on a photo capturing application.
My app only supports portrait mode and I have to rotate landscape images to rotate them for the portrait mode. For example I want to rotate the photo 90 degrees right if it was captured in landscapeRight.
But if user device is in "Lock screen orientation" mode, I can't get the correct device orientation value with UIDevice.current.orientation if user is trying to take a landscape positioned photo. It always returns "portrait" value of course due to the "lock screen oritentation".
I want to ask permission to user for unlocking screen orientation with like "This application wants to unlock your screen orientation" message. Is it possible to add my info.plist to add a permission request for unlocking screen orientation? And if yes, which permission do I have to add in my info.plist?
Thanks in advance.
I concur you can't change the orientation properties. All those properties (in your project page) do is to enable state variables and notifications from which you can animate the orientation of your UI. So perhaps a hacky solution would be to look at using gyroscope APIs, and to make a small algorithm based on that to detect device rotation. It would essentially come down to building logic similar to a Leveling App. https://developer.apple.com/documentation/coremotion/cmmotionmanager

iOS Is it possible to change orientation of device when default device rotation is off?

Today I was surprised by a feature of camera in apple when I rotate device to landscape mode icons were also rotated in landscape mode, Although the Automatic rotation was off for my device, How it can happen?
If default device rotation is off then how can camera app know that device orientation is changed?
I double checked my phones settings of Auto-Rotation and they were off.
The device-orientation setting is ignored for the camera. This was done so that people can keep orientation-lock on and take landscape photos at the same time, without having to constantly change the setting.

How to detect device rotation despite locked display orientation?

So I have an app that needs to not use autorotate. Instead of rotating the screen the buttons on the screen are just supposed to rotate.
I have the interface locked in landscape left. How do I detect what rotation the buttons should be?
I am using a custom opengl engine so I can set the rotation of objects.
You can get the device orientation from:
UIDevice.orientation
This is not the interface orientation, so you get two more possible values for face up and face down. Also the landscape left and right are swapped compared to UIInterfaceOrientation.
You can listen for changes in device orientation by subscribing to the UIDeviceOrientationDidChange notification from NSNotificationCenter. You may have to enable these notifications by calling UIDevice.beginGeneratingDeviceOrientationNotifications().
If the interface orientation is locked on the device, it is not listening to any delegate methods related to orientation changes.

UIDeviceOrientationDidChangeNotification event not firing when user disable screen auto-rotation

I can receive UIDeviceOrientationDidChangeNotification event, if auto-rotation is set.
But when screen auto rotation is disable, orientation notification doesn't work any more.
The effect I want to achieve is as iPhone Camera and Camera+: whatever the user lock or not lock the screen rotation, application can correspond to the rotation change immediately and correctly.
Does anyone has any idea why notification not sent when user lock the screen rotation?
How could I correspond to the device orientation change even if auto-rotation is disabled?
I also want to get the effect of the Camera app, where the app detects the orientation of the device even if the user has set Portrait Orientation Locked. UIDeviceOrientationDidChangeNotification is not posted when the user has portrait orientation locked. I believe the only way to determine the orientation of the device when the user has locked the orientation to portrait is to manually work out the orientation using UIAccelerometer.
The list of questions & answers below are all related to this issue. I found them when I was searching for an answer, and you might find them helpful too.
Related questions:
How to detect Camera Overlay view rotation
How to do Orientation Detection even the device has locked orientation
Detect iOS device orientation lock
Detect iPhone screen orientation
Callback method on auto rotation, iOS and iPad

Resources