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
Try
os(visionOS)
oros(xrOS)
. At the moment both names are correct.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 (checkProcessInfo.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