How to use requestGeometryUpdateWithPreferences in Objective C

1k views Asked by At

I have an example in Swift language:

    guard let windowScene = view.window?.windowScene else { return }
    windowScene.requestGeometryUpdate(.iOS(interfaceOrientations: .portrait)) { error in }

I can't write it in Objective C:

    UIWindowScene *windowScene = self.view.window.windowScene;
[windowScene requestGeometryUpdateWithPreferences:  UIInterfaceOrientationMaskPortrait errorHandler:nil];

Please tell me how to write correctly I will be grateful for any help.

1

There are 1 answers

0
HangarRash On

One way to write that Swift code in Objective-C would be:

UIWindowScene *windowScene = self.view.window.windowScene;
if (!windowScene) { return; }
UIWindowSceneGeometryPreferences *preferences = [[UIWindowSceneGeometryPreferencesIOS alloc] initWithInterfaceOrientations:UIInterfaceOrientationMaskPortrait];
[windowScene requestGeometryUpdateWithPreferences:preferences errorHandler:^(NSError * _Nonnull error) {
    // Handle error here
}];