Barcode Detection Enterprise API

I am attempting to use the Barcode Detection enterprise API. I have the necessary entitlements and license file. I'm following the sample code online, and whenever I attempt to run the barcode detection using arKitSession.run I get the following error message:

ar_barcode_detection_provider_t <0x300d82130>: Failed to run provider with transient error code: 1

It obviously isn't running the barcode detection, even though it's running in an immersive space in mixed mode. Any idea what might be going on?

struct BarcodeView: View {
    @Environment(AppModel.self) var appModel
    @State private var root = Entity()
    @State private var arKitSession = ARKitSession()
    
    
    var body: some View {
        RealityView { content, attachments in
            content.add(root)
            
            if let barcodeAttachment = attachments.entity(for: "testView") {
                barcodeAttachment.position = [0, 1, -1]
                root.addChild(barcodeAttachment)
            }
        } placeholder: {
            ProgressView()
        } attachments: {
            Attachment(id: "testView") {
                Text("Looking for barcodes")
                    .bold()
                    .font(.largeTitle)
            }
        }
        .task {
            guard BarcodeDetectionProvider.isSupported else {
                print("Barcode detection is not supported")
                return
            }
            
            await arKitSession.requestAuthorization(for: [.cameraAccess, .worldSensing])
            
            let barcodeDetection = BarcodeDetectionProvider(symbologies: [.code128, .code39, .code93, .ean8, .ean13, .qr, .upce])
            do {
                try await arKitSession.run([barcodeDetection])
                
                for await update in barcodeDetection.anchorUpdates {
                    switch update.event {
                        
                    case .added:
                        print("New barcode detected: \(update.anchor.payloadString ?? "")")
                    case .updated:
                        print("Barcode updated: \(update.anchor.payloadString ?? "")")
                    case .removed:
                        print("Barcode removed: \(update.anchor.payloadString ?? "")")
                    }
                }
                
            } catch {
                print("Error running ARKit session: \(error.localizedDescription)")
            }
            
            
        }
    }
}

Hello @jeremyfromtoledo

Barcode detection does not require camera access. Try changing:

await arKitSession.requestAuthorization(for: [.cameraAccess, .worldSensing])

to

await arKitSession.requestAuthorization(for: [.worldSensing])

Aside from that, your code looks good. If that doesn't fix the issue please try updating Xcode and visionOS (on your Vision Pro) and test again.

Please let me know how it goes.

@Vision Pro Engineer Thanks for responding. I did remove that code after posting this, and that did not make a difference. I also made sure my Vision Pro was updated to 2.0.1.

I'm using the standard template for an immersive space app and this is the code to launch my barcode immersive space. There's nothing missing in this part of the implementation is there?

import SwiftUI

@main
struct Enterprise3App: App {
    @State private var appModel = AppModel()
    @State private var avPlayerViewModel = AVPlayerViewModel()

    var body: some Scene {
        WindowGroup {
            if avPlayerViewModel.isPlaying {
                AVPlayerView(viewModel: avPlayerViewModel)
            } else {
                ContentView()
                    .environment(appModel)
            }
        }
        
        ImmersiveSpace(id: appModel.immersiveSpaceID2) {
            BarcodeView()
                .environment(appModel)
                .onAppear {
                    appModel.immersiveSpaceState = .open
                }
                .onDisappear {
                    appModel.immersiveSpaceState = .closed
                }
                
        }
        .immersionStyle(selection: .constant(.mixed), in: .mixed)
    }
}

Did you find the solution to this error? I'm trying to use the API too but am getting the same error.

@jeremyfromtoledo and @team_hcs

This behavior is unexpected and our teams need to investigate further. Can you please file a bug using feedback assistant (http://feedbackassistant.apple.com) and include a sysdiagnose? Instructions for capturing a sysdiagnose can be found here.

Please reply to this post with the feedback number so I can route it to the appropriate team.

@jeremyfromtoledo and @team_hcs

I spoke to the team responsible for the barcode API. The error you're seeing is not fatal and does not stop barcode detection from running. A few suggestions:

  • Triple check your entitlements and make sure your license file is part of your build target. This post contains tips to help you confirm enterprise api entitlements.
  • If you haven't already, try different bar codes to rule out input as the cause.

My entitlements look great, and there is no issue at compile time with them matching up to what's in the portal. I've confirmed that the Enterprise.license file is included in the target membership for the project.

I've even gone so far as to create an additional project from the Xcode template, used .mixed immersionStyle, and copy the code from the example directly into ImmersiveView.swift. I still get that error message and the app absolutely does not pick up and type of bar code. I've added all the available symbologies, and tried scanning both QR codes and barcodes on the back of an iPhone box and also a standard UPC code, to no avail.

It really seems that the code published (https://developer.apple.com/documentation/visionos/locating-and-decoding-barcodes-in-3d-space) to attempt barcode scanning is missing something in order to get it to work properly.

@team_hcs have you gotten barcode scanning to work yet?

HI @jeremyfromtoledo

Thanks for checking your entitlements and replying so quickly. I have successfully ran the code you referenced on several occasions, but I want to give you a better answer than "it works on my machine". Can you file a feedback request that includes a sysdiagnose (instructions in a previous post) and reply with the feedback number? I want to unblock you and get to the bottom of this.

As an aside, if you are not in an immersive space you won't get frames, but your code seems to indicate you are in an immersive space. Can you confirm you are?

Unfortunately the link that you sent I get an "Unauthorized Access" page when clicking on it, even when signed in with the account holder role.

I can confirm that I am using an immersive space. I've even replaced the barcode detection .task with the task from this sample code (https://developer.apple.com/documentation/visionos/setting-up-access-to-arkit-data) and I have no problem detecting planes in the await update in planeData.anchorUpdates code block. Is there any chance something is wrong with my Enterprise.license file that would cause this?

Also, you mentioned that you've ran my code and it seems to be working just fine. Can you confirm you see the same message that I do in the console when running barcode detection? The ar_barcode_detection_provider_t <0x303ee4a20>: Failed to run provider with transient error code: 1 message?

the same problem

@jeremyfromtoledo

Thanks for being patient. I missed your reply. Can you try this link https://developer.apple.com/bug-reporting/profiles-and-logs/?platform=visionos. Scroll down to where is says Sysdiagnose and click the instructions link.

@jeremyfromtoledo

I forgot to add, yes an invalid license file would cause this behavior.

@jeremyfromtoledo I'm running into the same issue with spatial barcode scanning. Have you come across any solutions for this?

Barcode Detection Enterprise API
 
 
Q