IOS沙箱Files目錄說明和常用操作

來源:互聯網
上載者:User

標籤:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

 

 

    // 讀取Documents目錄代碼

    NSArray *pathsDocuments=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);

    NSString *pathDocuments=[pathsDocuments objectAtIndex:0];

//    NSLog(@"pathDocuments~~~~~~%@    pathsDocuments----%@",pathDocuments,pathsDocuments);

  /*

   pathDocuments~~~~~~/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/12EA0817-D2C0-40E5-B3CC-1EB642FCDF9F/Documents    pathsDocuments----(

   "/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/12EA0817-D2C0-40E5-B3CC-1EB642FCDF9F/Documents"

   )

   */

 

 

   // 讀取Cache目錄代碼

    NSArray *pathsCache=NSSearchPathForDirectoriesInDomains(NSCachesDirectory,NSUserDomainMask,YES);

    NSString *pathCache=[pathsCache objectAtIndex:0];

//    NSLog(@"pathCache~~~~~~%@    pathsCache----%@",pathsCache,pathCache);

    /*

     pathCache~~~~~~(

     "/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/823489C8-00DA-403B-95AB-76C8FBE8AAAA/Library/Caches"

     )    pathsCache----/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/823489C8-00DA-403B-95AB-76C8FBE8AAAA/Library/Caches

     */

 

 

    // 讀取Library目錄

    NSArray *pathsLibrary=NSSearchPathForDirectoriesInDomains(NSLibraryDirectory,NSUserDomainMask, YES);

    NSString *pathLibrary=[pathsLibrary objectAtIndex:0];

//    NSLog(@"pathsLibrary~~~~~~%@    pathLibrary----%@",pathsLibrary,pathLibrary);

    /*

     pathsLibrary~~~~~~(

     "/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/05969A2D-E6BD-4F4B-A57E-4414D987D240/Library"

     )    pathLibrary----/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/05969A2D-E6BD-4F4B-A57E-4414D987D240/Library

 

     */

 

     // 讀取temp檔案夾

    NSString *tempDir=NSTemporaryDirectory();

//    NSLog(@"tempDir~~~%@",tempDir);

   /*

    tempDir~~~/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Data/Application/CEF70855-6285-46D9-B7BF-B4C9AAB1816B/tmp/

 

    */

 

    // 項目內建的.bundle資產庫放在.bundle中這些資源唯讀不能寫

    NSString *defaultDBPath=[[NSBundle mainBundle] resourcePath];

    NSLog(@"defaultDBPath~~%@",defaultDBPath);

  /*

   defaultDBPath~~/Users/yhj/Library/Developer/CoreSimulator/Devices/65FC33FE-6234-427B-A4F2-4F22ACE36842/data/Containers/Bundle/Application/D94DD7F5-0CE9-4EEF-8E47-37C4737EF2CF/IOS沙箱Files目錄說明和常用操作.app

   */

 

 

 

    // 可以保證app的documents檔案內容不備份到icloud上

    [self addSkipBackupAttributeToItemAtURL:[NSURL fileURLWithPath:pathDocuments]];

    return YES;

}

 

// 用NSURLIsExcludedFromBackupKey 或 kCFURLIsExcludedFromBackupKey 檔案屬性來防止檔案被備份。這些API是通過通過舊的,棄用的方式的直接設定額外屬性。所有運行在iOS5.1的都應該使用這些API包防止檔案被備份。在iOS5 .1上防止檔案被備份

-(BOOL)addSkipBackupAttributeToItemAtURL:(NSURL *)URL

{

    assert([[NSFileManager defaultManager] fileExistsAtPath:[URL path]]);

    NSError *error=nil;

    BOOL success=[URL setResourceValue:[NSNumber numberWithBool:YES] forKey:NSURLIsExcludedFromBackupKey error:&error];

    if (!success) {

        NSLog(@"Error excluding %@ from backup %@",[URL lastPathComponent],error);

    }

    return success;

}

IOS沙箱Files目錄說明和常用操作

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.