display.save fails to save occasionally

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;
}

try to use display.save() without checking disk space on the same devices that failed to save
if it fails then the problem is in display.save() if it does not then the problem is in checking the disk space

I think it is not possible to get the precise remaining space by code on the ios device.
So when the device has more than 100M of space left, my app still may not be able to save a file only 100k.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.