Newbie Apple dev here. I am used to Android devices environment, hence we have an app that creates config files in local app folder, files we can access by the file browser when needed.
I understand that there will never be such possibility (to access app folder from a browser) on VisionOS, so I tried to make the app save the files (.json) to an accessible folder (downloads, documents, whatever.)
Thing is I have zero idea on how to do this on VisionOS, and can’t find any doc. Can a kind Apple-lover soul direct me to some documentation or explain how to do this using a Unity app ? Thanks.
This came up before here, although that uses some Objective-C code. There’s another thread here discussing how to do it on iOS (again recommending a native plugin). More often than not, solutions for iOS will work for visionOS as well.
This came up before here, although that uses some Objective-C code. There’s another thread here discussing how to do it on iOS (again recommending a native plugin). More often than not, solutions for iOS will work for visionOS as well.
Hi, thanks.
I gave up on this thread because I didn’t have enough Apple environment knowledge to know how to decipher some of the answers (how to grant authorizations, how to include objective C scripts in unity, etc.). But after some self-teaching I managed to expose the app’s files and write into “On my VisionPro/App folder/”.
But from what I understand, these files are deleted when the app is uninstalled, and the only other way to write in a permanent location would be iCloud, but I wasn’t successful with this.
Well at least I have a temporary folder, better than before
I understand that there will never be such possibility (to access app folder from a browser) on VisionOS,
Just go to to files icon in the app screen, then select “On My Apple Vision Pro” under locations. All the folders for apps will be listed there, if the app uses local storage. You can access folders for any app there.
You can create a folder for your own app (or let the app do it) and copy files and folders into it as needed.
The other links in the replies will show you the code to access the folder, called the documents folder.
Here’s sample code in Swift;
func getAppFolderItemURLS()
{
guard let documentsDirectory = getLocalDocumentsDirectory() else
{
return
}
do {
let testFile = documentsDirectory.appendingPathComponent("test3.txt")
try? "hello".write(to: testFile, atomically: true, encoding: .utf8)
// List all files in the "On My Apple Vision Pro" -> [Your App] folder
let fileURLs = try FileManager.default.contentsOfDirectory(at: documentsDirectory, includingPropertiesForKeys: nil)
print("Files: \(fileURLs)")
for i in 0..<fileURLs.count
{
resourceFolders[fileURLs[i].lastPathComponent] = fileURLs[I]
}
} catch {
print("Error listing files: \(error)")
}
}
func getLocalDocumentsDirectory() -> URL?
{
// Find the app's Documents directory
let paths = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)
return paths.first
}