'UIScreen' is unavailable in visionOS, how to fix it? Is there anything to replace UIScreen?

'UIScreen' is unavailable in visionOS, how to fix it? Is there anything to replace UIScreen?

Thanks.

Accepted Reply

Hi @JingDu , take a look at this WWDC video (Meet UIKit for spatial computing). At 4:16, the presenter references UIScreen and why it cannot be used. You can conditionalize out problematic code, as she does in the video, as you should not need to read the values of it for visionOS.

  • Try using UIWindowScene if you need something else!

Add a Comment

Replies

Hi @JingDu , take a look at this WWDC video (Meet UIKit for spatial computing). At 4:16, the presenter references UIScreen and why it cannot be used. You can conditionalize out problematic code, as she does in the video, as you should not need to read the values of it for visionOS.

  • Try using UIWindowScene if you need something else!

Add a Comment

Thank you so much.

My workaround for now, taking sidebar visibility into consideration.

var screenWidth: Int? = nil
if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene {
    if splitViewVisibility == .detailOnly {
        screenWidth = Int(windowScene.coordinateSpace.bounds.width)
    }else{
        screenWidth = Int(windowScene.coordinateSpace.bounds.width) - 320
    }
}