iosuiimagepickercontrolleruiinterfaceorientationios13.1.2

iOS 13 orientation changed forcefully


I have an app and it's working fine as expected in iOS 12 and below. I am only supporting portrait mode in my app. Now in iOS 13 what happens is If I open camera to capture video and rotates the device camera rotates but when I tap on choose video my app also shows rotated in landscape. Anyone knows anything about this ?

UPDATE

The issue appears again but randomly whenever we dismiss a presented view controller. anyone knows anything about this ?


Solution

  • I fixed the issue by setting portrait orientation in delegate callbacks of UIImagePickerController. The issue was only appearing when we are opening camera directly only with video option. If we open camera with Photo and Video option. It works perfectly fine.

    - (void)setPortraitOrientation {
        [[UIDevice currentDevice] setValue:@(UIInterfaceOrientationPortrait) forKey:@"orientation"];
        [UINavigationController attemptRotationToDeviceOrientation];
    }
    
    - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {
        [self setPortraitOrientation];
        [picker dismissViewControllerAnimated:YES completion:NULL];
    }
    
    - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    
        [self setPortraitOrientation];
    
        [picker dismissViewControllerAnimated:YES completion:^{
    
        }];
    }