DEV Community

Ting
Ting

Posted on

检测app是否运行在visionOS的临时方法

TL;DR

/// A Boolean indicating whether the current device is running visionOS or not.
private let isOnVisionOS = NSClassFromString("UIWindowSceneGeometryPreferencesVision") != nil
Enter fullscreen mode Exit fullscreen mode

需要注意的点:

  • 目前(202411)这是一个较为简单的检测方法。苹果还未提供官方API来实现这个功能。source
  • 这个检测无法判断app是处于iPadOS兼容性模式,还是visionOS原生模式运行。

Top comments (0)

👋 Kindness is contagious

Immerse yourself in a wealth of knowledge with this piece, supported by the inclusive DEV Community—every developer, no matter where they are in their journey, is invited to contribute to our collective wisdom.

A simple “thank you” goes a long way—express your gratitude below in the comments!

Gathering insights enriches our journey on DEV and fortifies our community ties. Did you find this article valuable? Taking a moment to thank the author can have a significant impact.

Okay