I’m trying to save a file (a .glb 3D model) generated in my VisionOS app to the Files app so it’s accessible to users. Despite my efforts, the file doesn’t show up in the “On My Apple vision pro” section of the Files app.
What I do:
-
The Info.plist has an entry of UIFileSharingEnabled set to true
-
I’m using a .mm file with objective-c code that saves the file to the documents folder:
// Save a file to the app's Documents directory and delete the original file
extern "C" void SaveFileToDocuments(const char* filePath) {
NSString* path = [NSString stringWithUTF8String:filePath];
NSString* fileName = [path lastPathComponent];
// Get the Documents directory
NSURL* documentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] firstObject];
NSURL* destinationPath = [documentsDirectory URLByAppendingPathComponent:fileName];
// Check if the file exists at the source path
if (![[NSFileManager defaultManager] fileExistsAtPath:path]) {
NSLog(@"Source file does not exist at path: %@", path);
return;
}
// Delete the existing file in the destination path, if any
if ([[NSFileManager defaultManager] fileExistsAtPath:[destinationPath path]]) {
NSError* deleteError = nil;
[[NSFileManager defaultManager] removeItemAtPath:[destinationPath path] error:&deleteError];
if (deleteError) {
NSLog(@"Failed to delete existing file at destination: %@", deleteError.localizedDescription);
return;
}
}
// Copy the file to the Documents directory
NSError* copyError = nil;
[[NSFileManager defaultManager] copyItemAtPath:path toPath:[destinationPath path] error:©Error];
if (copyError) {
NSLog(@"Error copying file to Documents: %@", [copyError localizedDescription]);
} else {
NSLog(@"File successfully saved to: %@", [destinationPath path]);
}
}
I have verified that the file is copied successfully to the documents folder, but it doesnt show up in files, Any ideas?
Thanks in advance!