I am using GCDWebServer library to create a http server on my tvos device. When I do so, the server link successfully opens the web page associated with the server. However, it throws 500 error on any API that I hit(using the buttons on webpage provided by GCDWebUploader) like listing files or uploading a file.
When I build the same code on Apple TV simulator. It works fine and lists files and uploads and downloads is working fine.
I've tried changing ports but to no avail. I've also tried different directories like let documentDirectoryURL = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first, FileManager.default.urls(for: .applicationSupportDirectory, in: .userDomainMask).first and still no luck. But when I use let documentDirectoryURL = FileManager.default.temporaryDirectory it works on both simulator and actual Apple TV.
I have found an app on app store that uses the same GCDWebServer library(maybe they tinkered with it a bit). And the files have been saved on their app for many days. That means it is permanent. So my question is why does it run on Simulator with permanent directory. Also how is it that I am unable to store permanent files but there are apps out there that are able to do so.
My code is
private func createServer(){
// This directory is accessible on Apple TV simulator but not on Apple TV device
let documentsDirectory = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
// This directory is accessible on both Apple TV simulator and Apple TV device
let temporaryDirectory = FileManager.default.temporaryDirectory
// Initialize the web uploader
webUploader = GCDWebUploader(uploadDirectory: temporaryDirectory.path)
webUploader.delegate = self
// Start the web server
try webUploader.start()
print("Web server started: \(webUploader.serverURL)")
serverUrlLbl.text = webUploader.serverURL?.absoluteString
}
My Apple TV OS version is 15.5.1 while simulator is 16.4