We found that using display.save to save files on iOS devices is sometimes unsuccessful.
We use display.save to save an image, and we will delay 200 milliseconds to check if the file exists. Most of the time the file exists, however, we found from the error logs that there are still many devices that the file does not exist. We have checked whether the devices have enough disk space left before saving.
This problem persisted for a long time, we did not find out where the problem occurred.
Here is the code we use to check the remaining disk space.
uint64_t
PluginStorage::getFreeDiskspace( lua_State *L ) {
uint64_t totalSpace = 0;
uint64_t totalFreeSpace = 0;
NSError *error = nil;
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];
if (dictionary) {
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];
NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
} else {
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %ld", [error domain], (long)[error code]);
}
lua_pushnumber(L, (totalSpace/1024ll)/1024ll);
lua_setfield( L, -2, "totalSpace" );
lua_pushnumber(L, (totalFreeSpace/1024ll)/1024ll);
lua_setfield( L, -2, "freeSpace" );
return totalFreeSpace;
}