admin管理员组

文章数量:1296914

I am on Xcode 16.2 and running a simulator for iOS 18.2. Previously, I was on Xcode 15.x and running iOS 17.4 sims. This problem did not occur for me on iOS 17.4. Sample code is as follows:

import SwiftUI
import PhotosUI

struct ContentView: View {
    @StateObject var imagePicker2 = ImagePicker()
    var body: some View {
        ScrollView {
            VStack {
                Image(systemName: "globe")
                    .imageScale(.large)
                    .foregroundStyle(.tint)
                Text("Hello, world!")
                   .background(Color.orange)
                   .padding(.bottom, 75)
                PhotosPicker(selection: $imagePicker2.imageSelection, matching: .images, photoLibrary: .shared()) {
                    Label("", systemImage: "photo")
                }
                .font(.system(size: 55))
                .padding(.bottom, 55)
                if let image = imagePicker2.image {
                    HStack {
                        image
                            .resizable()
                            .frame(width:75, height:75)
                            .scaledToFit()
                            .overlay(Rectangle().stroke(Color.teal, lineWidth: 2))
                    }
                }
            }
            .padding()
        }
   }

}

import SwiftUI
import PhotosUI
@MainActor
class ImagePicker: ObservableObject {
    @Published var unableToLoad: Bool = false
    @Published var image: Image?
    @Published var myUIImage: UIImage?
    @Published var imageSelection: PhotosPickerItem? {
        didSet {
            unableToLoad = false
            if let imageSelection {
                //.. try to convert photosPickerItem imageSelection into a uiImage
                Task {
                    try await setImage(from: imageSelection)
                }
            }
        }
    }
    func setImage(from imageSelection: PhotosPickerItem?) async throws {
        do {
            if let data = try await imageSelection?.loadTransferable(type: Data.self) {
                if let uiImage = UIImage(data: data) {
                    self.image = Image(uiImage: uiImage)
                    self.myUIImage = uiImage
                }
            }
        } catch {
            print(error.localizedDescription)
            unableToLoad = true
        }
    }
}

The image loads on the UI but I get "[ERROR] Could not create a bookmark: NSError: Cocoa 4097 "connection to service named com.apple.FileProvider" in the log every time I choose a new photo. So far, I haven't had an actual crash but others have indicated that depending on what they're doing code-wise, that some have crashed. Is this an iOS 18.x bug? Thoughts?

I am on Xcode 16.2 and running a simulator for iOS 18.2. Previously, I was on Xcode 15.x and running iOS 17.4 sims. This problem did not occur for me on iOS 17.4. Sample code is as follows:

import SwiftUI
import PhotosUI

struct ContentView: View {
    @StateObject var imagePicker2 = ImagePicker()
    var body: some View {
        ScrollView {
            VStack {
                Image(systemName: "globe")
                    .imageScale(.large)
                    .foregroundStyle(.tint)
                Text("Hello, world!")
                   .background(Color.orange)
                   .padding(.bottom, 75)
                PhotosPicker(selection: $imagePicker2.imageSelection, matching: .images, photoLibrary: .shared()) {
                    Label("", systemImage: "photo")
                }
                .font(.system(size: 55))
                .padding(.bottom, 55)
                if let image = imagePicker2.image {
                    HStack {
                        image
                            .resizable()
                            .frame(width:75, height:75)
                            .scaledToFit()
                            .overlay(Rectangle().stroke(Color.teal, lineWidth: 2))
                    }
                }
            }
            .padding()
        }
   }

}

import SwiftUI
import PhotosUI
@MainActor
class ImagePicker: ObservableObject {
    @Published var unableToLoad: Bool = false
    @Published var image: Image?
    @Published var myUIImage: UIImage?
    @Published var imageSelection: PhotosPickerItem? {
        didSet {
            unableToLoad = false
            if let imageSelection {
                //.. try to convert photosPickerItem imageSelection into a uiImage
                Task {
                    try await setImage(from: imageSelection)
                }
            }
        }
    }
    func setImage(from imageSelection: PhotosPickerItem?) async throws {
        do {
            if let data = try await imageSelection?.loadTransferable(type: Data.self) {
                if let uiImage = UIImage(data: data) {
                    self.image = Image(uiImage: uiImage)
                    self.myUIImage = uiImage
                }
            }
        } catch {
            print(error.localizedDescription)
            unableToLoad = true
        }
    }
}

The image loads on the UI but I get "[ERROR] Could not create a bookmark: NSError: Cocoa 4097 "connection to service named com.apple.FileProvider" in the log every time I choose a new photo. So far, I haven't had an actual crash but others have indicated that depending on what they're doing code-wise, that some have crashed. Is this an iOS 18.x bug? Thoughts?

Share Improve this question asked Feb 11 at 17:30 KatMKatM 2212 silver badges15 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 3

I received this response from Apple. I just wanted to post it here in case anyone else is encountering this:


Thanks for sharing your post and the code. The error message you're encountering on the console, "[ERROR] Could not create a bookmark: NSError: Cocoa 4097 "connection to service named com.apple.FileProvider", is a known issue. It's related to the FileProvider framework and is scheduled to be resolved in a future version of iOS. Rest assured, this error:

  • Does not crash the app.
  • Does not throw an exception.
  • Should not impact the app's functionality during runtime.

It's primarily a debug-time message and can be safely ignored. We appreciate you bringing this to our attention. If you encounter any other issues, please don't hesitate to reach out.

本文标签: