Is there a `isiOSAppOnVision` flag to check iOS app on Vision Pro at runtime?

Hello,

When an iOS app runs on Vision Pro in compatible mode, is there a flag such as isiOSAppOnVision to determine the underlying OS at runtime? Just like the ProcessInfo.isiOSAppOnMac. It will be useful to optimize the app for visionOS.

Already checked but not useful:

  • #if os(xrOS) does not work in compatible mode since no code is recompiled.
  • UIDevice.userInterfaceIdiom returns .pad instead of .reality.

Thanks.

Answered by DTS Engineer in 802751022

Hello all,

There is no API to detect that an iOS app is running on visionOS. If you have not already, please file an enhancement request and detail your use-case for this functionality using Feedback Assistant.

Best regards,

Greg

FB12757613

The reasons for needing to distinguish the runtime environment include:

  1. App's custom UI controls and gestures need to be optimized for interaction on visionOS, such as the size of the touch area.
  2. Some user guide texts related to interaction in the app need to be distinguished for different platforms.
  3. The app sometimes needs to present to the user its type of device. It is very confusing for users to display Vision Pro as an iPad.

FB13465097

Can't you just check for the OS using #available? Seems to work for me.

extension UIDevice {    
    ///  True if running on vision pro
    var isVisionPro: Bool {
        if #available(visionOS 1.0, *) {
            return true
        } else {
            return false
        }
    }
}

Update: Realized this won't work. Will also be true on any non-vision OS.

you can use: ‘’‘swift‘’‘ static let isVisionProWindowDefaultSize = CGRectEqualToRect(CGRectMake(0, 0, 1194.0, 834.0), UIScreen.main.bounds) ‘’‘swift‘’‘ this is work,but unsafe.

For Apple Vision (Designed for iPad) there are NO solutions right now (WTF)

  1. is visionOS available will always return true
  2. screen bounds is... unsafe and future risky
  3. The obvious solution doesn't work and always returns false (see SO)
#if os(visionOS)
   print("We are in visionOS")
#else
   print("We are NOT in visionOS")
#endif

This is frustrating... I hope to find a solution soon, but I think it's on Apple.

A runtime check would be great, but the person compiling the app knows which they are targeting (a compatible iPad app, or a visionOS app), so a custom compiler flag could be set and tested in the code with #if, right?

In Build Settings-> Swift Compiler - Custom Flags -> Active Compiler definitions -> add e.g. ISVISIONOS for a true visionOS app, and leave it out for iPad apps. The different Xcode targets have their own build settings.

and in swift: #if ISVISIONOS

Sorry if I'm missing something from your question.

Accepted Answer

https://medium.com/@timonus/low-hanging-fruit-for-ios-apps-running-on-visionos-08a85db0fb31

Hello all,

There is no API to detect that an iOS app is running on visionOS. If you have not already, please file an enhancement request and detail your use-case for this functionality using Feedback Assistant.

Best regards,

Greg

Is there a `isiOSAppOnVision` flag to check iOS app on Vision Pro at runtime?
 
 
Q