Group Group Group Group Group Group Group Group Group

Chapter 3 - broken ARSCNView?

I am trying to work my way through ARKit by Tutorials and am up to Chapter 3. I am trying to run the starter project, but it crashes with the console error:

2019-11-08 12:16:48.289985+1000 ARPokerDice[3172:1265809] *** Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named ARSCNView because no class named ARSCNView was found; the class needs to be defined in source code or linked in from a library (ensure the class is part of the correct target)'

*** First throw call stack:
(0x1bbfbcc30 0x1bbcd70c8 0x1bbeac3ac 0x1bf5ac5c0 0x1bf547428 0x1bfce87b0 0x1bf5ac700 0x1bf5ac934 0x1bf547428 0x1bfce36b0 0x1bfce62e8 0x1bfa1af08 0x1bfa1b9cc 0x1bfa1bc9c 0x1bfa1c384 0x1c008a94c 0x1c008a048 0x1c008afe4 0x1c009c1c8 0x1c004a42c 0x1c0050568 0x1bf7f8710 0x1bfca47e8 0x1bf7f9248 0x1bf7f8c78 0x1bf7f9064 0x1bf7f88e8 0x1bf7fd098 0x1bfcbe214 0x1bfbd1e90 0x1bfcbe1cc 0x1bf7fcdb0 0x1bfcbe0b4 0x1bf7fcc0c 0x1bf668630 0x1bf6670f4 0x1bf668360 0x1c004e91c 0x1bfbf3d7c 0x1c1126014 0x1c114cbd0 0x1c11310f8 0x1c114c864 0x10530b2a8 0x10530e9d0 0x1c1173384 0x1c1173030 0x1c117359c 0x1bbf38260 0x1bbf381b4 0x1bbf37920 0x1bbf327ec 0x1bbf32098 0x1c609c534 0x1c00527ac 0x104b6cef0 0x1bbdb1f30)
libc++abi.dylib: terminating with uncaught exception of type NSException

If I add the line:
let _ = ARWorldTrackingConfiguration()
to the method initARSession(), then it does not crash.

I don’t quite understand why ARSCNView could not be instantiated, as it should be loaded via the storyboard (if I am correct).

I was using Xcode 11.1, and just upgraded to 11.2 and the problem remains.

I bought the eBook last week. I have the exact same problem. Did you manage to solve the problem?

Ok got it. Apparently they forgot to mention - or i didn’t read it - that you need to add code inside the initARSession() function. So just go on with the tutorial. Otherwise just paste this into initARSession() function:

guard ARWorldTrackingConfiguration.isSupported else {
        print("***ARConfig: AR World Tracking Not Supported")
        return
    }
    
    let config = ARWorldTrackingConfiguration()
    config.worldAlignment = .gravity
    config.providesAudioData = false
    sceneView.session.run(config)

that should do the trick

@brunzbus Thank you for sharing your solution - much appreciated! :]

I just wanted to add that it seems the problem is that XCode is not linking the ARKit framework because it is not being used yet in the starter project. Although ARKit is being imported into the file, without actually referencing any of it’s properties it seems to not be automatically linked in the build settings. I assume some sort of optimization step is skipping the include since it’s not used. I found that just adding a single line of code that references a variable in the framework fixes the issue. For example:

ARFaceTrackingConfiguration.isSupported 

Alternatively if you click on your project root, go to build phases / Link Binary with Libraries / and manually add ARKit.framework then it should get rid of that error. (or that worked for me. I’m new to XCode so I may be missing details)