Issue
This issue is reproducible on iOS 17 beta 4 and iOS 17.0 (21A5303d) public beta.
When try to create a folder using the FileManager
API, the app crashes with the following stack trace.
Thread 1: Fatal error: 'try!' expression unexpectedly raised an error: Error Domain=NSCocoaErrorDomain Code=513 "You don’t have permission to save the file “Samples” in the folder “…”." UserInfo={NSURL=file://…/Samples.app/, NSUnderlyingError=0x28100cf00 {Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted"}}
What is the user impact?
Users will not be able to run the app on iOS 17
Steps to Reproduce
- Create a new project
- Add the following code
import SwiftUI
struct ContentView: View {
var body: some View {
Text("Hello, world!")
.onAppear {
_ = makeTemporaryDirectory()
}
}
/// Creates a temporary directory.
private func makeTemporaryDirectory() -> URL {
try! FileManager.default.url(
for: .itemReplacementDirectory,
in: .userDomainMask,
appropriateFor: Bundle.main.bundleURL,
create: true
)
}
}
- Build and run the app. It crashes on the force try line.
O/S: iOS 17 (Beta 4) / iOS 17.0 (21A5303d)
Device: iPad Pro Gen 4, iPhone 11. Only happens on real device, not on the simulators
I suspect that you’re seeing the error because of this: File system changes introduced in iOS 17. You’ve told FileManager
to find you the replacement directory that’s appropriate for Bundle.main.bundleURL
. Now that your app is on a different volume than your container, that’s no longer possible.
Where do you ultimately plan to save your files? In your app’s Documents directory? If so, call this API twice, once to get the location of the Documents directory and then again to get a replacement directory that’s appropriate for that.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"