Reputation: 726
I builded a func that worked for me in some of my aplications. sharing text as a pdf file. In a new project (iOS15) I wanted to reuse this func, but getting a depreciated messages. I don't understand how should I change my code to the new UIWindow.Scene.windows.
The message shows up at two positions in my code (marked <--- here)
--> 'windows' was deprecated in iOS 15.0: Use UIWindowScene.windows on a relevant window scene instead
How could I change my code to be compatible with iOS 15?
func sharePDF(pdf: Data) {
let pdfData = pdf
let printingDate = Datum()
let temporaryFolder = FileManager.default.temporaryDirectory
let fileName = "Scan2Clipboard " + printingDate + ".pdf"
let temporaryFileURL = temporaryFolder.appendingPathComponent(fileName)
do {
try pdfData.write(to: temporaryFileURL)
let vc = UIActivityViewController(activityItems: [temporaryFileURL], applicationActivities: nil)
if UIDevice.current.userInterfaceIdiom == .pad {
vc.popoverPresentationController?.sourceView = UIApplication.shared.windows.first <--- here
vc.popoverPresentationController?.sourceRect = CGRect (
x: UIScreen.main.bounds.width / 2.1,
y: UIScreen.main.bounds.height / 2.3,
width: 300, height: 300)
}
UIApplication.shared.windows.first?.rootViewController?.present(vc, animated: true, completion: nil) <--- here
} catch {
print(error)
}
}
Upvotes: 2
Views: 2522
Reputation: 368
this has been updated for iOS 15
UIApplication
.shared
.connectedScenes
.compactMap { $0 as? UIWindowScene }
.flatMap { $0.windows }
.first { $0.isKeyWindow }
.rootViewController?.present()
Upvotes: 4