I have a sandboxed application that opens a file that has been chosen by the NSOpenPanel (or .fileImporter as it is a SwiftUI).
The permissions are set properly with for the sandbox (see screenshot)
After recompiling with Xcode 15.3 (and also with 15.2) the permission is not granted anymore and I cannot open the file anymore. An exception is thrown with The file “someFile.csv” couldn’t be opened because you don’t have permission to view it.
.
Is there something new, that needs to be done, so that this works again? If I turn off the sandbox the file opens without any problem.
It is even reproducible with a completely new application with the following simple code:
import SwiftUI
import UniformTypeIdentifiers
@main
struct IFinanceCleanerApp: App {
var body: some Scene {
WindowGroup {
ContentView()
}
}
}
struct ContentView: View {
@State private var url: URL?
@State private var showErrorDialog = false
@State private var showImporter = false
@State private var lastError: Error?
var body: some View {
Button("Show") {
showImporter = true
}
.fileImporter(isPresented: $showImporter, allowedContentTypes: [.commaSeparatedText]) { result in
switch result {
case .success(let openUrl):
url = openUrl
do {
let strings = try String(contentsOf: openUrl)
} catch {
showErrorDialog = true
lastError = error
}
case .failure(let error):
print("Open Panel failed: \(error.localizedDescription)")
}
}
.alert("Opening File failed", isPresented: $showErrorDialog) {
Button("OK") {}
} message: {
Text(lastError?.localizedDescription ?? "")
}
}
}