swiftuiswiftui-navigationstackphotospicker

SwiftUI PhotosPicker - AXRuntimeError and detached view controller warning


I have the following code in a View that I show via a NavigationStack path.push() statement:

@State private var avatarItem: PhotosPickerItem?
@State private var avatarImage: Image?

var body: some View {
    VStack(alignment: .center) {
        VStack {
            if let avatarImage {
                avatarImage
                    .resizable()
                    .frame(width: 200, height: 250)
                    .foregroundColor(.gray)
                    .padding()
            } else {
                Image("profile")
                    .resizable()
                    .frame(width: 200, height: 200)
                    .foregroundColor(.gray)
                    .padding()
            }
                
            PhotosPicker(selection: $avatarItem) {
                Label("Select a Photo", systemImage: "photo.artframe")
            }
            .padding()
            // process a selected image from the photo library
            .onChange(of: avatarItem) { newValue in
                Task {
                    if let imageData = try? await newValue?.loadTransferable(type: Data.self), let image = UIImage(data: imageData) {
                        avatarImage = Image(uiImage: image)
                    }
                }
            } etc...

It works and the selected image is displayed properly, but the console shows the following errors (plural):

2023-08-07 15:48:48.165282-0600 xxxapp[5190:599015] [AXRuntimeCommon] AX Lookup problem - errorCode:1100 error:Permission denied portName:'com.apple.iphone.axserver' PID:5199 (
0   AXRuntime                           0x00000001d37ccacc _AXGetPortFromCache + 968
1   AXRuntime                           0x00000001d37cf038 AXUIElementPerformFencedActionWithValue + 852
2   UIKit                               0x0000000232cf1ef0 4FEFF55E-05A3-3C88-9310-3F5FA9CFE3CD + 790256
3   libdispatch.dylib                   0x00000001026b4520 _dispatch_call_block_and_release + 32
4   libdispatch.dylib                   0x00000001026b6038 _dispatch_client_callout + 20
5   libdispatch.dylib                   0x00000001026be0b0 _dispatch_lane_serial_drain + 984
6   libdispatch.dylib                   0x00000001026bedf4 _dispatch_lane_invoke + 412
7   libdispatch.dylib                   0x00000001026cbc74 _dispatch_workloop_worker_thread + 736
8   libsystem_pthread.dylib             0x00000002084c4ddc _pthread_wqthread + 288
9   libsystem_pthread.dylib             0x00000002084c4b7c start_wqthread + 8

This view is a couple of levels into my NavigationStack. I've toyed with moving some of the logic into the main thread, but that has not helped.

The error

2023-08-07 15:58:40.433125-0600 xxxapp[5264:603960] [AXRuntimeCommon] Unknown client: xxxapp

appears when the PhotoPicker is tapped and displayed, the rest when it returns.

I also get a detached view controller error when this view is displayed, is that related? (Haven't figured that one out, yet, early days.)

2023-08-07 15:58:40.199165-0600 xxxapp[5264:603580] [Presentation] Presenting view controller <_TtGC7SwiftUI29PresentationHostingControllerVS_7AnyView_: 0x10602c800> from detached view controller <_TtGC7SwiftUI32NavigationStackHostingControllerVS_7AnyView_: 0x105824400> is discouraged.

I'm using Xcode 14.3.1, target of iOS 16.4. The AXRuntime errors only appears on-device, not in the simulator.

I have also tried making this run on the main thread, no change.

TIA!


Solution

  • Apparently this is an iOS bug. Thank you devdchaudhary