For SwiftUI, when you want to present the ActivityViewController you can do with 3 steps like the code below
Deprecated Code
guard let urlShare = URL(string: "https://apple.com") else { return }
let activityVC = UIActivityViewController(activityItems: [urlShare], applicationActivities: nil)
// 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead
UIApplication.shared.windows.first?.rootViewController?.present(activityVC, animated: true, completion: nil)
There are similar questions
But in the case of presenting the UIActivityViewController, the view doesn't not present at all, and it presents the error log
UIApplication.shared.connectedScenes
.filter({$0.activationState == .foregroundActive})
.map({$0 as? UIWindowScene})
.compactMap({$0})
.first?.windows
.filter({$0.isKeyWindow})
.first?.rootViewController?.present(activityVC, animated: true, completion: nil)
[Presentation] Attempt to present
<UIActivityViewController: 0x10f015e00> on
<_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x10290e570>
(from <_TtGC7SwiftUI19UIHostingControllerGVS_15ModifiedContentVS_7AnyViewVS_12RootModifier__: 0x10290e570>)
which is already presenting
<_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10a923870>.
What is the equivalent of this code in iOS 15?
UIApplication.shared.windows.first?.rootViewController?.present(activityVC, animated: true, completion: nil)