skip to Main Content

I have a video analysis app and i’m trying to make it compatible with visionOS. It crashes because camera is not allowed; Apple only allows to import videos from Photos.

So I would need to check on launch if the device runs visionOS to show the photos picker rather than the camera view, similarly to what I use right now to check if I’m on macCatalyst or iOS:

#if targetEnvironment(macCatalyst)
   print("We are in macOS Catalyst")
#else
   print("We are in iOS")
#endif

Thanks in advance.

2

Answers


  1. Try os(visionOS) or os(xrOS). At the moment both names are correct.

    #if os(visionOS)
       print("We are in visionOS")
    #else
       print("We are in iOS")
    #endif
    
    Login or Signup to reply.
  2. I believe you’re running your iOS app directly on visionOS, without recompiling the code against the visionOS SDK, correct?

    If so, the app is in compatible mode, and any conditional compile directives like #if os(xrOS) won’t work. It’s similar to an iOS app running on a Mac with Apple Silicon (check ProcessInfo.isiOSAppOnMac).

    However, I haven’t found a suitable API to determine if an iOS app is running on visionOS at runtime.

    Forum Link: https://developer.apple.com/forums/thread/733029

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search