Since iOS 26:
import UIKit
UIApplication.shared.sendAction(#selector(UIResponderStandardEditActions.performClose(_:)), to: nil, from: nil, for: nil)
Ensure that the UIApplication.shared responder hierarchy contains a valid first responder, otherwise app may not respond to system actions like closing