'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 Answer

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.

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
    }
}

Hello engineer, I would like to inquire about a question regarding the migration of iPhone code to VisionPro devices. There is a login scenario issue that I am unable to resolve. The login page has an input box called UItextfield, and I have customized the keyboard on the login page, textfield.inputview = my_keyboard, When the user inputs the password, the custom keyboard my_keyboard that pops up is displayed normally on the phone. The width of the custom keyboard is the same as the width of the phone screen. However, in this scenario on the VisionPro device, the width and height of the VisionPro window that I set is CGSize (7501200). At this time, the app displays the width and height of the size that I set. But when the password input box is clicked, the width of the custom keyboard my_keyboard that pops up is much wider than the width that I set, which is 750. The effect I want is that on the VisionPro device, the width of the custom keyboard displayed through inputView is the same as the width that I set. How can this problem be solved? Thank you very much.

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