githubEdit

Detect Mobile Devices and Platforms

Learn how to detect mobile devices, tablets, browsers, and operating systems to create platform-specific experiences

Learn how to detect what device, platform, or browser your users are on to create optimized experiences.

Needle Engine provides the DeviceUtilities namespace with functions to detect:

  • Device types: Mobile phones, tablets, desktops, XR headsets

  • Operating systems: iOS, Android, macOS, VisionOS

  • Browsers: Safari, Chrome, specialized XR browsers

  • Capabilities: AR support, microphone permissions, version info

Use these utilities to adapt your app's behavior, optimize performance, or enable platform-specific features.

:::tip Cross-Platform by Default Needle Engine works seamlessly across all platforms! Use these utilities only when you need platform-specific features or optimizations. Your app should work everywhere by default, with progressive enhancement for capable devices. :::


Built-In Components (No Code Required!)

For many use cases, you don't need to write any code! Use these built-in components directly in Unity or Blender.

DeviceFlag Component

Automatically show or hide GameObjects based on device type (mobile vs desktop).

In Unity/Blender:

  1. Add the DeviceFlag component to any GameObject

  2. Set Visible On to:

    • Desktop - Only visible on desktop/laptop computers

    • Mobile - Only visible on phones and tablets

    • Desktop + Mobile - Visible on all devices

Use Cases:

  • Show high-quality models only on desktop

  • Display simplified UI for mobile devices

  • Hide complex effects on lower-powered devices

XRFlag Component

Show or hide objects based on XR state (VR/AR mode, first/third person view).

In Unity/Blender:

  1. Add the XRFlag component to any GameObject

  2. Set Visible In to combinations of:

    • Browser - Normal web browser mode

    • AR - When in AR session

    • VR - When in VR session

    • FirstPerson - First-person camera view

    • ThirdPerson - Third-person camera view

Use Cases:

  • Show UI only in browser mode, hide in VR/AR

  • Display different models for VR vs AR

  • Switch between first-person and third-person controls

:::tip Perfect for Non-Programmers These components work automatically when added in your editor - no scripting needed! They're perfect for artists and designers who want device-specific content without writing code. :::


Quick Start (Code)

:::tip Recommended Approach Use the DeviceUtilities namespace for all device detection - it keeps imports clean and organized. :::


Device Type Detection

Mobile vs Desktop

Specific Device Types


Operating System Detection

iOS Detection

Android Detection

macOS Detection


Browser Detection

Safari

Chrome

Specialized Browsers


XR and AR Capabilities

AR Support

VR Devices


Practical Examples

Platform-Specific Quality Settings

Adaptive UI

Control Scheme Selection

Feature Detection with Permissions


Available Detection Functions

All functions are available under the DeviceUtilities namespace. See the complete API documentationarrow-up-right for more details.

Device Types

  • DeviceUtilities.isMobileDevice() - Any phone or tablet

  • DeviceUtilities.isDesktop() - Desktop/laptop computer (excludes Hololens)

  • DeviceUtilities.isiPad() - iPad specifically

  • DeviceUtilities.isQuest() - Meta Quest devices

  • DeviceUtilities.isVisionOS() - Apple Vision Pro

Operating Systems

  • DeviceUtilities.isiOS() - Any iOS device (iPhone, iPad, iPod, Vision Pro)

  • DeviceUtilities.isAndroidDevice() - Android devices

  • DeviceUtilities.isMacOS() - macOS computers

Browsers

  • DeviceUtilities.isSafari() - Safari browser

  • DeviceUtilities.isMozillaXR() - Mozilla XR Viewer

Capabilities

  • DeviceUtilities.supportsQuickLookAR() - AR QuickLook support (iOS AR)

  • DeviceUtilities.microphonePermissionsGranted() - Async check for microphone access

Version Information

  • DeviceUtilities.getiOSVersion() - Returns iOS version string

  • DeviceUtilities.getChromeVersion() - Returns Chrome version string

  • DeviceUtilities.getSafariVersion() - Returns Safari version string


Best Practices

Progressive Enhancement

Always build your core experience to work on all platforms, then enhance:

Test on Real Devices

Device detection isn't perfect. Always test on actual hardware:

  • Use URL parameters for testing: ?forcemobile=true

  • Test on multiple iOS and Android versions

  • Verify behavior in different browsers

Combine with Feature Detection

Prefer feature detection over device detection when possible:


Next Steps

Learn more:

Reference:

Last updated