ios – How to set InterfaceOrientation lock when button cliked in SwiftUI



Before ios 16 it was implemented like this

AppDelegate.orientationLock = .portrait
UIDevice.current.setValue(UIInterfaceOrientation.portrait.rawValue, forKey: "orientation")

now code is

AppDelegate.orientationLock = .landscape
let windowScene = SceneDelegate.window?.windowScene
windowScene?.requestGeometryUpdate(.iOS(interfaceOrientations: .landscape), errorHandler: { error in })

But now this doesn’t change the orientation lock
I want to change the orientation lock every time the button is pressed, is there any other way?

And is there a way to change the orientation lock when the button is clicked?