preferredInterfaceOrientationForPresentation method is invalid in iOS16 beta6 version

  1. First of all, my program supports Portrait, Left and Right

  2. Customize an AViewCOntroller, AViewCOntroller supports orientation Portrait, Left, Right, click on the screen to create a BViewCOntroller object and rotate it to landscape.()

@interface AViewCOntroller ()
@end

@implementation AViewCOntroller

#pragma mark - life method
- (void)viewDidLoad{
  [super viewDidLoad];
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
  return UIInterfaceOrientationMaskAllButUpsideDown;
}

#pragma mark - event method
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  BViewCOntroller *vc =[[BViewCOntroller alloc] init];
  [self presentViewController:vc animated:YES completion:nil];
  [self _dealOrientation:UIInterfaceOrientationMaskLandscapeLeft vc:vc];
}

- (void)_dealOrientation:(UIInterfaceOrientationMask)orientation vc:(UIViewController *)vc{
  if (@available(iOS 16.0, *)) {
    if (vc) {
      NSArray *array = [[[UIApplication sharedApplication] connectedScenes] allObjects];
      UIWindowScene *ws = (UIWindowScene *)array[0];
      UIWindowSceneGeometryPreferencesIOS *geometryPreferences = [[UIWindowSceneGeometryPreferencesIOS alloc] init];
      geometryPreferences.interfaceOrientations = orientation;
      [ws requestGeometryUpdateWithPreferences:geometryPreferences
                    errorHandler:^(NSError * _Nonnull error) {
      }];
      [vc setNeedsUpdateOfSupportedInterfaceOrientations];
    }
  } else {
    [[UIDevice currentDevice] setValue:@(UIDeviceOrientationUnknown) forKey:@"orientation"];
    [[UIDevice currentDevice] setValue:@(orientation) forKey:@"orientation"];
  }
}

@end
  1. window.rootViewController = [[AViewCOntroller alloc] init]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  self.window.rootViewController = [[AViewCOntroller alloc] init];
  [self.window makeKeyAndVisible];
  return YES;
}
  1. Customize an BViewCOntroller,BViewCOntrollersupports orientation Portrait, Left, Right。Implemented the preferredInterfaceOrientationForPresentation method。
@interface BViewCOntroller : UIViewController 
@end 

@implementation BViewCOntroller 
- (void)viewDidLoad { [super viewDidLoad]; } 

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
 return UIInterfaceOrientationMaskAllButUpsideDown; 
} 

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
  return UIInterfaceOrientationLandscapeLeft;
}

@end 
  1. When the program is run at this time, the device orientation defaults to vertical screen, so the first time the AViewCOntroller interface is loaded is also vertical screen. At this time, click the screen to create a BViewCOntroller object. Result: Before iOS16, preferredInterfaceOrientationForPresentation took effect, and BViewCOntroller was displayed horizontally for the first time. In IOS16 Bate 6, preferredInterfaceOrientationForPresentation is invalid, and BViewCOntroller will be displayed vertically for the first time.

runs the program The device runs the program in the vertical screen state, and the appearance is as follows: In versions before iOS16, the AViewController in the vertical screen is displayed first, and the BViewController in the horizontal screen is displayed after clicking the AViewController. For iOS16 Bate version, the AViewController in the vertical screen is displayed first, and the BViewController in the vertical screen is displayed after clicking the AViewController.

The above phenomenon is obviously that the preferredInterfaceOrientationForPresentation method is invalid in the iOS16 beta6 version,These two different phenomena I think are bugs in the iOS16 Bate version.

preferredInterfaceOrientationForPresentation method is invalid in iOS16 beta6 version
 
 
Q