Article

Building a Basic AR Experience

Configure an AR session and use SceneKit or SpriteKit to display AR content.

Overview

When you use the ARSCNView or ARSKView class, ARKit automatically manages the basic requirements for creating an AR experience: Each view displays a live camera image as its backdrop and renders the 2D or 3D overlay content you provide to create the illusion of that content inhabiting the real world. To use one of these view classes, you configure it for the kind of AR experience you want to create, and choose positions and representations for your overlay content.

To build your own view for an AR experience instead, see Displaying an AR Experience with Metal.

Configure and Run the AR Session

Both the ARSCNView and ARSKView classes include an ARSession object that manages the motion tracking and image processing required to create an AR experience. However, to run a session you must provide a session configuration.

The ARWorldTrackingSessionConfiguration class provides high-precision motion tracking and enables features to help you place virtual content in relation to real-world surfaces. In situations where world tracking is not available, the base class ARSessionConfiguration provides simple motion tracking that permits less immersive AR experiences.To start an AR session, create a session configuration object with the options you want, then call the run(_:options:) method on the session object of your ARSCNView or ARSKView instance:

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)
    
    // Create a session configuration
    let configuration = ARWorldTrackingSessionConfiguration()
    configuration.planeDetection = .horizontal
    
    // Run the view's session
    sceneView.session.run(configuration)
}

After you’ve set up your AR session, use SceneKit or SpriteKit to place virtual content in the view.

Topics

Next Steps

Providing 3D Virtual Content with SceneKit

Use SceneKit to add realistic three-dimensional objects to your AR experience.

Providing 2D Virtual Content with SpriteKit

Use SpriteKit to place two-dimensional images in 3D space in your AR experience.

See Also

Standard Views

class ARSCNView

A view for displaying AR experiences that augment the camera view with 3D SceneKit content.

Beta
class ARSKView

A view for displaying AR experiences that augment the camera view with 2D SpriteKit content.

Beta