Updated code for Sharesheet in iOS 15?

I'm trying to display a share sheet and am using examples from the Internet but am getting the following warning:

"'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead"

Here's the code I'm trying to use:

func shareButton()
{
  let url = URL(string: introText)

  let av = UIActivityViewController(activityItems: [url!], applicationActivities: nil)

 UIApplication.shared.windows.first?.rootViewController?.present(av, animated: true, completion: nil)
}

Thanks, Dan Uff

am using examples from the Internet > You should better visit the author of the code.

I did. He said that he didn’t know either.

Better avoid using such a code that no one is responsible for.

with SwiftUI you must implement an UIViewControllerRepresentable in order to load a UIKit.

struct ActivityViewController: UIViewControllerRepresentable {
	var itemsToShare: [Any]
	var servicesToShareItem: [UIActivity]? = nil
	func makeUIViewController(context: UIViewControllerRepresentableContext<ActivityViewController>) -> UIActivityViewController {
		let controller = UIActivityViewController(activityItems: itemsToShare, applicationActivities: servicesToShareItem)
		return controller
	}
	func updateUIViewController(_ uiViewController: UIActivityViewController,
								context: UIViewControllerRepresentableContext<ActivityViewController>) {}
}

and then on your view you should implement a .sheet to load this UIActivityViewController.

YourView()
		.sheet(isPresented: $showShareSheet, content: { ActivityViewController(itemsToShare: [YourDataHereToShare]) })

the shareSheet is not perfect yet, I'm still figuring out too. hence why I'm here too :)

Thank you, and it’s nice to know I’m not the only one who’s seeking an answer.

Updated code for Sharesheet in iOS 15?
 
 
Q