Initiate ARView with the specified dimensions, camera mode, and session configuration state.

Hello


Ready some post and documentation.

If finally tryied to launch an ARView in nonAR mode.


Here is the documentation I read:

https://developer.apple.com/documentation/realitykit/arview/3340492-init


So Given a fresh new Xcode project setup using Augmented Reality App configuration for iOS default.

I just modified the code a little (see below)


import UIKit
import RealityKit

class ViewController: UIViewController {
   
    @IBOutlet var arView: ARView!
   
    override func viewDidLoad() {
        super.viewDidLoad()
       
        setupArView()
       
        // Load the "Box" scene from the "Experience" Reality File
        let boxAnchor = try! Experience.loadBox()
       
        // Add the box anchor to the scene
        arView.scene.anchors.append(boxAnchor)
    }
   
    func setupArView() {
        let frameRect = CGRect(x: 0, y: 0, width: 100, height: 100)
        let cameraMode = ARView.CameraMode.nonAR
       
       
       
        arView = ARView(frameRect: frameRect, cameraMode: cameraMode, automaticallyConfigureSession: false)
       
    }
}


When I look at the error of XCode editor:


I have:

On line 22

Type 'ARView' has no member 'CameraMode' ... that is a very bad news


Any clue / or sample code ?


Regards

Accepted Reply

As mentioned, if your target is simulator or not iOS you can not specify the cameraMode, it will go straight to nonAR. The only initialiser will just take the frame I believe.


Only if you are building for an iOS device (not simulator) can you use the initialiser with cameraMode.


#if os(iOS) && !targetEnvironment(simulator)
arView.cameraMode = .nonAR
#endif


No need to recreate the ARView, just changing the camera mode should be fine.


If you are still stuck it'd be useful to know what your build target is.

Replies

Make sure you’re building for a target iOS device, and not the simulator. Only on iOS can you specify the cameraMode, Simulator and macOS can only work with nonAR.

I am not able to build since I have an error in the Editor.


My question is how can I setup ma arView to be launch in nonAR ? Since, my syntax is not appropriate.

As mentioned, if your target is simulator or not iOS you can not specify the cameraMode, it will go straight to nonAR. The only initialiser will just take the frame I believe.


Only if you are building for an iOS device (not simulator) can you use the initialiser with cameraMode.


#if os(iOS) && !targetEnvironment(simulator)
arView.cameraMode = .nonAR
#endif


No need to recreate the ARView, just changing the camera mode should be fine.


If you are still stuck it'd be useful to know what your build target is.

Thank you maxxfrazer.


I could not think that choosing a build target have an impact of how the Editor is behaving.

And yet ...


When I take my initial code and change the target to be my iPhone... No more warning.

Have a nice day.