开发者

Storing data in the app sandbox - what if the user runs out of space?

开发者 https://www.devze.com 2022-12-17 16:39 出处:网络
I am storing some images locally in my app\'s sandbox. I currently have the minimum set at 10MB, and will be allowing the user to choose how much storage is allowed (up to 500MB).

I am storing some images locally in my app's sandbox. I currently have the minimum set at 10MB, and will be allowing the user to choose how much storage is allowed (up to 500MB).

In the scenario that the app is installed on a device where there's simple no space开发者_如何学运维 on it, or if there's 1MB space left and I start saving a 2MB image what happens?


Your save method will fail and throw an NSFileWriteOutOfSpaceError.

If you handling a lot of disk space this might useful to you.

Edit:
To the space left, you can use this code:

NSDictionary *fsAttr = [ [NSFileManager defaultManager] fileSystemAttributesAtPath:NSTemporaryDirectory()]; 
NSNumber *totalFreeSize = [fsAttr objectForKey:NSFileSystemFreeSize];
0

精彩评论

暂无评论...
验证码 换一张
取 消