Sandbox 文件存放规则

文档1, document2,  document3

 

一、文件路径介绍

<Application_Home>/AppName.app :

  1) This is the bundle directory containing the app itself.

  2) Do not whrite anything to this directory.

  3) iCloud and iTunes do not back up.

 

<Application_Home>/Documents :

  1) Store critical data that not be recreated by your app.

  2) Will be copied to the new app directory while app update

  3) The contents of this directory are backed up by iTunes.

 

<Application_Home>/Decuments/Inbox :

  1) Use this directory to access files that your app was asked to open by oputside entities. Specifically, the Mail program places email attachments whit your app in this directory.

  2) Your app can read and delete files in this directory but cannot create new files or write to existng files. If the user tries to edit a file in this directory, your app must silently move it out of the directory before making any changes.

  3) The contents of this directory are backed up by iTunes.

 

<Application_Home>/tmp :

  1) Temporary data comprises any data that you do not need to presist for an extended period of time.

  2) Remember to delete those files when you are done with them so that do not continue to consume space on the user's device.

  3) iCloud and iTunes do not back up.

 

<Application_Home>/Library/ :

  1) Store not user data files. You typically put files in one of serveral standard subdirectories but you can also create custom subdirectory files you want to backed up but not exposed to the user.

  2) Will be copied to the new app directory while app update.

  3) The contents of this directories (with the exception of the caches subdirectory) are backed up by iTunes. 

 

<Application_Home>/Library/Caches :

  1) Database cache files and downloadable content.

  2) Your app should be able to handle situations where cached data is deleted by the system to free up disk space.

  3) iCloud and iTunes do not back up.

 

  注意:获取文件路径最好使用 NSSearchPathForDirectoriesInDomains, 不要使用 [NSHomeDirectory() stringByAppendingString: @“xxxxx"]。(if Apple ever chooses to rename or move the Documents directory, your app will break.)

 

二、Prevent backup

  1) ios 5.1 and later, 

    Add the NSURLIsExcludedFromBackupKey attribute to the corresponding NSURL object using the serResourceValue:forKey:error: method.

  2) ios 5.0.1 use

  3) iOS 5.0 and earlier, It is not possible to exclude data from backups on iOS 5.0. If your app must support iOS 5.0, then you will need to store your app data in Caches to avoid that data being backed up.

-(BOOL) addSkipBackupAttributeToItemAtURL: (NSURL *)URL {
    assert([fileManager fileExistsAtPath: [URL path]]);
    
    if ([BROKER.context.device ifSystemMeetRequireVersion: @"5.1"]) {
        NSError* error = nil;
        BOOL success = [URL setResourceValue: [NSNumber numberWithBool: YES]
                                      forKey:NSURLIsExcludedFromBackupKey error:&error];
        return success;
        
    } else if ([BROKER.context.device ifSystemMeetRequireVersion: @"5.0.1"]) {
        const char* filePath = [[URL path] fileSystemRepresentation];
        const char* attrName = "com.apple.MobileBackup";
        u_int8_t attrValue = 1;
        int result = setxattr(filePath, attrName, &attrValue, sizeof(attrValue), 0, 0);
        return (result == 0);
    }
    
    return YES;
}

 

三、统计文件夹的大小 

 

转载于:https://www.cnblogs.com/eileenleung/p/3504282.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值