UIScreen.main.scale
will deprecated.
here it the document in UIKit.UIScreen
@available(iOS, introduced: 2.0, deprecated: 100000, message: "Use a UIScreen instance found through context instead: i.e, view.window.windowScene.screen")
open class var main: UIScreen { get } // the device's internal screen
deprecated: 100000
means to be deprecated.
So my question is how do I replace this method?
use below method can work in main App, but UIApplication.shared
doesn't available in extension app. Is there any solution to resolve this problem
@available(iOSApplicationExtension, unavailable)
extension UIWindow {
static var current: UIWindow? {
for scene in UIApplication.shared.connectedScenes {
guard let windowScene = scene as? UIWindowScene else { continue }
for window in windowScene.windows {
if window.isKeyWindow { return window }
}
}
return nil
}
}
@available(iOSApplicationExtension, unavailable)
extension UIScreen {
static var current: UIScreen? {
UIWindow.current?.screen
}
}